Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: insert lines based on some pattern

by Mandrake (Chaplain)
on Feb 16, 2007 at 07:03 UTC ( [id://600371]=note: print w/replies, xml ) Need Help??


in reply to insert lines based on some pattern

By the term "order", do you mean similar ones should be grouped ?
If so, a quick solution can be
my %hash; for (@filenames) { chomp; push @{$hash{$3}}, $_ if ($_ =~ /(.+)\/(.+)\/(.+)\/.+/); } for (keys %hash) { print "#".uc($_)."\n" ; print $_."\n" for (@{$hash{$_}}); print "#END ".uc($_)."\n" ; }
This uses a hash. You can print the output to a file.

Replies are listed 'Best First'.
Re^2: insert lines based on some pattern
by CountZero (Bishop) on Feb 16, 2007 at 10:12 UTC
    If you look carefully at the sample output, you will see that the order of the files is maintained with files in the same type to be "surrounded" by "bakery" or "fruitjunction" tags.

    Your hash-of-arrays will not keep this "interleaved" order.

    CountZero

    "If you have four groups working on a compiler, you'll get a 4-pass compiler." - Conway's Law

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-03-28 17:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found