Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Help to split

by reisinge (Friar)
on Mar 16, 2013 at 10:22 UTC ( #1023826=note: print w/replies, xml ) Need Help??


in reply to Help to split

Hello, another way (more suitable for a beginner?) to do it:

#!/usr/bin/perl use strict; use warnings; # Get the filename as command line argument my $filename = shift; open my $fh, "<", $filename or die "Can't open $filename"; while ( my $line = <$fh> ) { # go through file, line by line my @fields = split ':', $line; my ($first) = split /\s+/, $fields[4]; print "$first\n"; } close $fh;

Excellence is an art won by training and habituation: we do not act rightly because we have virtue or excellence, but we rather have these because we have acted rightly. -- Will Durant

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023826]
help
Chatterbox?
[marto]: It's not worse, just different. Different shells, different tools. Different ways
[choroba]: Perl to the rescue!
[choroba]: yes, it's documented in man bash. You need to echo 'Joe'\''s home'
[marto]: That's on my list of t-shirts to sell "Perl to the rescue", " I hate Oracle"....

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2017-11-24 10:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (346 votes). Check out past polls.

    Notices?