craziestfire73 has asked for the wisdom of the Perl Monks concerning the following question:
how can I create this program more concise. I'm new to PEARL so I'm still learning the tricks. Any assistance would be really appreciated. The code works, I just want to make it more neat and short. I feel like I'm writing too much code for what it does. I keep experimenting with regex but I can't seem to make it work using regex.
#!/usr/bin/perl opendir(CURRENT,"."); @list = readdir(CURRENT); closedir(CURRENT); my $string = "messages"; my $x = 0; foreach $item(@list){ if($item =~ /^$string\.*\d*/){ open(FILE,"$string"); open(FILE1,"$string.1"); open(FILE2,"$string.2"); open(FILE3,"$string.3"); open(FILE4,"$string.4"); $content = <FILE>; $content1 = <FILE1>; $content2 = <FILE2>; $content3 = <FILE3>; $content4 = <FILE4>; while($content == $x){ print ($content, $content1, $content2, $content3, $content4); $x++; close(/FILE\d*/); } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Perl: Directoriesand files
by Anonymous Monk on Mar 30, 2011 at 10:19 UTC | |
by JavaFan (Canon) on Mar 30, 2011 at 10:22 UTC | |
by Anonymous Monk on Mar 30, 2011 at 11:37 UTC | |
by JavaFan (Canon) on Mar 30, 2011 at 11:38 UTC | |
by Anonymous Monk on Mar 30, 2011 at 11:49 UTC | |
| |
by craziestfire73 (Initiate) on Mar 30, 2011 at 10:30 UTC | |
|
Re: Perl: Directoriesand files
by JavaFan (Canon) on Mar 30, 2011 at 10:21 UTC | |
by JavaFan (Canon) on Mar 30, 2011 at 11:37 UTC | |
by craziestfire73 (Initiate) on Mar 30, 2011 at 10:32 UTC | |
by jethro (Monsignor) on Mar 30, 2011 at 10:44 UTC | |
by craziestfire73 (Initiate) on Mar 30, 2011 at 11:11 UTC | |
by jethro (Monsignor) on Mar 30, 2011 at 11:22 UTC | |
|