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

Perhaps the following will assist you with your coding:

use Modern::Perl; my %files; while (<DATA>) { next unless /^(\d+.\d+.\d+.\d+)/; chomp; push @{ $files{$1} }, $_; } for my $ip ( keys %files ) { do { say "Zip $_ -> $ip.zip" } for @{ $files{$ip} }; } __DATA__ 192.168.1.1somestring.txt 192.168.1.1anotherRANDOMstring.txt 192.168.1.1.somerandom.docx 192.168.1.3somestring.txt 192.168.1.3anotherRANDOMstring.txt 192.168.1.3.somerandom.docxx

Output:

Zip 192.168.1.1somestring.txt -> 192.168.1.1.zip Zip 192.168.1.1anotherRANDOMstring.txt -> 192.168.1.1.zip Zip 192.168.1.1.somerandom.docx -> 192.168.1.1.zip Zip 192.168.1.3somestring.txt -> 192.168.1.3.zip Zip 192.168.1.3anotherRANDOMstring.txt -> 192.168.1.3.zip Zip 192.168.1.3.somerandom.docx -> 192.168.1.3.zip

Hope this helps!

Replies are listed 'Best First'.
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
    my apology the 192.168.1.1 is an example and it will be random so the ip is unknown

      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
        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>;