Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Syntactic Confectionery Delight
 
PerlMonks  

Re^2: needing to zip files in a series that begin with the same IP address

by diamondsandperls (Beadle)
on Jul 27, 2012 at 21:14 UTC ( #984103=note: print w/ replies, xml ) Need Help??


in reply to Re: needing to zip files in a series that begin with the same IP address
in thread needing to zip files in a series that begin with the same IP address

my apology the 192.168.1.1 is an example and it will be random so the ip is unknown


Comment on Re^2: needing to zip files in a series that begin with the same IP address
Re^3: needing to zip files in a series that begin with the same IP address
by Kenosis (Priest) on Jul 27, 2012 at 21:16 UTC

    It's OK if the IPs are random, as your regex will match any IPv4 address. Those in the data set are just for the example script. That is, you'll need to to code the grabbing of the actual file names.

      currently i am not zipping anything the code only prints the screen the Zip portion at the bottom of the screen when i run the code. i just used your code as is
      Zip 192.168.1.1somestring.txt -> 192.168.1.1 Zip 192.168.1.1anotherRANDOMstring.txt -> 192.168.1.1 Zip 192.168.1.1.somerandom.docx -> 192.168.1.1 Zip 192.168.1.3somestring.txt -> 192.168.1.3 Zip 192.168.1.3anotherRANDOMstring.txt -> 192.168.1.3 Zip 192.168.1.3.somerandom.docx -> 192.168.1.3

        See my follow-up posting below.

      man im clueless on this i know how to regex for my file list just not sure how to apply to the code you gave.
      #!perl use strict; use warnings; use Modern::Perl; use IO::Compress::Zip qw(zip $ZipError) ; my %files; while (<DATA>) { next unless /^(\d+.\d+.\d+.\d+)/; push @{ $files{$1} }, $_; } for my $ip ( keys %files ) { do { print "Zip $ip -> $_" } for @{ $files{$ip} }; } __DATA__ my @files = <*.txt *.docx>;

        Hi, diamondsandperls.

        You're certainly not clueless, as you've mostly done this work yourself.

        Sorry, but I didn't mean to confuse the issue by using __DATA__, but it was for example only (gives a source of the data for the script). So, you can use what you've already done like this:

        use Modern::Perl; use IO::Compress::Zip qw(zip $ZipError) ; my %files; my @files = <*.txt *.docx>; for (@files) { next unless /^(\d+.\d+.\d+.\d+)/; push @{ $files{$1} }, $_; } for my $ip ( keys %files ) { do { print "Zip $ip -> $_" } for @{ $files{$ip} }; }

        Place your zipping call within the do{} block (replacing the printing placeholder), noting that $ip contains the common IP address and $_ contains the complete file name to be zipped.

        ps Modern::Perl contains both strict and warnings.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (4)
As of 2014-04-21 00:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (489 votes), past polls