Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Newbie to PERL removing text from array

by Erez (Curate)
on Feb 14, 2012 at 12:19 UTC ( #953693=note: print w/ replies, xml ) Need Help??


in reply to Newbie to PERL removing text from array

This mainly depends on the file format. If you can be 100% sure that this, and only this is the way lines will be presented, then you can do the following:

my @output; foreach my $line (@lines) { my @split = split ' ', $line; #split by whitespace pop @split if $split[0] eq '*'; #getting rid of leading * $split[0] =~ s/\.//g #remove the dots from the element push @output, $split[0] . ' ' . $split[3]; }

Otherwise, you'll need to do a foreach on each of @split's elements, match them to a pattern and use those that you need.

Principle of Least Astonishment: Any language that doesnít occasionally surprise the novice will pay for it by continually surprising the expert


Comment on Re: Newbie to PERL removing text from array
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2015-07-28 06:04 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 (252 votes), past polls