Connecting Tech Pros Worldwide Forums | Help | Site Map

processing /etc/fb.modes help

Newbie
 
Join Date: Oct 2007
Location: England
Posts: 2
#1: Oct 16 '07
Hi i am new to Perl and i was wondering if you could look at my scripts and give me advice and feedback on how i could improve my scripts.

I am using /etc/fb.modes to write Perl scripts.

script 1- This script will read in the file and print one line at a time
#!/usr/bin/perl
open(INFO, `/etc/fb.modes`);
while($line = <INFO>)
{
print $line;
}
close INFO;

Skip comments and empty lines
#!/usr/bin/perl
open(INFO, `/etc/fb.modes`);
next if $line = ~ /^#/; #skips comments
next if $line =//; #skips emptylines
while($line = <INFO>)
{
print $line;
}
close INFO;


skips endmode lines
#!/usr/bin/perl
open(INFO, `/etc/fb.modes`);
next if $line = ~ /^#/; #skips comments
next if $line =//; #skips emptylines
next if $line =endmode;
while($line = <INFO>)
{
print $line;
}
close INFO;

How would i skip lines beginning with whitespace?

i want to split the header line in /etc/fb.modes
i want to split where the hyphens are and print out the first 2 fields on separate lines
for example
mode "640X480
75"
This is what ive done

#!/usr/bin/perl
open(INFO, `/etc/fb.modes`);
@line = split /-/, "mode "640X480-75";
print mode "\n" ;
print 75"\n";
print "=========================" "\n"; # i did this so its easy to read

Member
 
Join Date: Sep 2007
Posts: 63
#2: Oct 16 '07

re: processing /etc/fb.modes help


You can use the chomp() operator to skip the empty lines.

Chomp is a operator exactly to "get rid" of newline characters.
I'm a newbie in Perl either but I guess it's probably what you need.

good luck,

Joćo
KevinADC's Avatar
Expert
 
Join Date: Jan 2007
Location: Southern California USA
Posts: 4,091
#3: Oct 16 '07

re: processing /etc/fb.modes help


Quote:

Originally Posted by jcor

You can use the chomp() operator to skip the empty lines.

Chomp is a operator exactly to "get rid" of newline characters.
I'm a newbie in Perl either but I guess it's probably what you need.

good luck,

Joćo

chomp() dos not skip blank/empty lines.
Member
 
Join Date: Sep 2007
Posts: 63
#4: Oct 17 '07

re: processing /etc/fb.modes help


Quote:

Originally Posted by KevinADC

chomp() dos not skip blank/empty lines.


Ok
Like I said, I was not sure.

Sorry to make confusion,

Joćo
Reply