Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Parsing a line of text

by pvaldes (Chaplain)
on Mar 13, 2013 at 17:14 UTC ( #1023263=note: print w/ replies, xml ) Need Help??


in reply to Parsing a line of text

in pseudocode

# we read the /etc/shadow to a filehandle open (my $filehandle, '<', '/etc/shadow') or die $!; while (<$filehandle>){ # we read line by line now chomp; # and split the line by fields my ($name, $passwd, $field3, $field4,... ETC until $field8) = split /: +/ $_; if ($passwd = '*'){do something...} elsif ($passwd = '!'){do other...} } # we close the while loop close $filehandle;

Updated: you don't need to double the !! probably

Updated again: missed a semicolon after die


Comment on Re: Parsing a line of text
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023263]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (15)
As of 2015-07-28 18:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (258 votes), past polls