Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

Perhaps you should also look at using operators like push, for example in your code:

my (@commands,@matches,$ip); for (my $i=0; $i < @temp; $i++){ #process each subset if ($i == 0){ my @temp1 = split(/:/, $temp[0]); #this is the fir +st subset, it contains the IP $ip = $temp1[0]; $count++; $temp[0] =~ s/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9 +][0-9]?)\.){3}(?:25[0-5]|2[0-4 +][0-9]|[01]?[0-9][0-9]?)://; #remove IP from subset } my @arr; if ($temp[$i] =~ /\=/ ){ #this subset contains pattern +-matching instructions my @temp2 = split(/\=/, $temp[$i]); #split subset +into further subsets, first co +ntaining the command, the rest are patterns $temp2[0] = substitute_placeholders($temp2[0],\@me +tachars,\@translations); #all +splitting is done on this string, revert it back to its original form $commands[$i] = $temp2[0]; #this is the command for (my $c=1; $c < @temp2; $c++){ #these are all t +he patterns $temp2[$c] = substitute_placeholders($temp2[$c +],\@metachars,\@translations); + ##undo prior substitutions $arr[$c] = $temp2[$c]; } $matches[$i] = \@arr; }else{ #this subset does not contain pattern matching +instructions $temp[$i] = substitute_placeholders($temp[$i],\@me +tachars,\@translations); ##und +o prior substitutions $commands[$i] = $temp[$i]; $arr[$i] = "no-match-hook"; ##set flag for easy id +entification later on in the s +cript $matches[$i] = \@arr; } } $$DATA{$ip}->{commands} = \@commands; $$DATA{$ip}->{matches} = \@matches;

It looks like you could use push instead of array indexes.    Something like this:

my ( @commands, @matches, $ip ); for my $i ( 0 .. $#temp ) { #process each subset if ( $i == 0 ) { my @temp1 = split /:/, $temp[ 0 ]; #this is the fi +rst subset, it contains the IP $ip = $temp1[ 0 ]; $count++; $temp[ 0 ] =~ s/^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0 +-9][0-9]?)\.){3}(?:25[0-5]|2[0-4 +][0-9]|[01]?[0-9][0-9]?)://; #remove IP from subset } my @arr; if ( $temp[ $i ] =~ /=/ ) { #this subset contains patt +ern-matching instructions my @temp2 = split /=/, $temp[ $i ]; #split subset +into further subsets, first co +ntaining the command, the rest are patterns push @commands, substitute_placeholders( $temp2[ 0 + ], \@metachars, \@translations ); #all +splitting is done on this string, revert it back to its original form for my $c ( 1 .. $#temp2 ) { #these are all the pa +tterns push @arr, substitute_placeholders( $temp2[ $c + ], \@metachars, \@translations ); + ##undo prior substitutions } push @matches, \@arr; } else { #this subset does not contain pattern matchin +g instructions push @commands, substitute_placeholders( $temp[ $i + ], \@metachars, \@translations ); ##und +o prior substitutions push @arr, "no-match-hook"; ##set flag for easy id +entification later on in the s +cript push @matches, \@arr; } } $$DATA->{ $ip }{ commands } = \@commands; $$DATA->{ $ip }{ matches } = \@matches;

In reply to Re^7: RFC: beginner level script improvement by jwkrahn
in thread RFC: beginner level script improvement by georgecarlin

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (6)
    As of 2014-07-26 17:19 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      My favorite superfluous repetitious redundant duplicative phrase is:









      Results (178 votes), past polls