Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Re: Parsing in perl

by McDarren (Abbot)
on Jun 09, 2009 at 16:05 UTC ( #769979=note: print w/replies, xml ) Need Help??

in reply to Parsing in perl

Hi :)

You're doing a lot of convulted stuff there with arrays and C-style loops, that really isn't necessary.

When you need to examine a file line by line, you're usually better reaching for a 'while' loop, rather than a 'for' loop.

Here is a slightly more perlish way to do what you want.

#!/usr/bin/perl use strict; use warnings; my $le = 'lethal_results.txt'; open my $in, '<', $le or die "Cannot open $le:$!\n"; while (<$in>) { chomp; my $foo = (split)[4]; print "$foo\n" if $foo >= 50; } close $in;
Of course, you could always just do something like:
perl -lane 'print $F[4] if $F[4] >= 50' < lethal_results.txt

Darren :)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://769979]
Discipulus is Corion reading 'Gory details of parsing quoted constructs'?..
[perldigious]: That's awesome erix. One of my work friends, who coincidentally convinced me to learn Perl originally, has a Finnish pen-pal. I showed him this and he immediately wanted to send it along to her.
[perldigious]: Also coincidentally, I'm currently in the middle of a winter storm that has dropped 1 foot of snow and is expected to drop another. I might have to adapt this for customers/vendors who come visit and put it at the beggining of every presentation I give.
[Discipulus]: the photo was removed... Cyrano de Berjerac was not of the same idea..

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (12)
As of 2016-12-06 16:22 GMT
Find Nodes?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:

    Results (112 votes). Check out past polls.