in reply to Break a file into seperate files based on string match

Hi, what have you tried, and how did it not work for you?

Update: ahh, what's the use? Don't copy this:

use strict; use warnings; use feature 'say'; use Path::Tiny; my %file_map = ( tag1 => Path::Tiny->tempfile, tag2 => Path::Tiny->tem +pfile ); chomp( my @lines = <DATA> ); for ( @lines ) { my ( $txt, $tag ) = split / : /; path( $file_map{ $tag } )->append("$txt\n"); } for ( keys %file_map ) { say $file_map{ $_ }; say $file_map{ $_ }->slurp; } __END__ test/foo/bar : tag1 test/abc/xyz : tag1 test/def/abc : tag2 test/bar/foo : tag2 test/dummy/foo : tag1
Output:
perl 1206430.pl /tmp/k6iEPAjgjR test/def/abc test/bar/foo /tmp/aFliecLlJN test/foo/bar test/abc/xyz test/dummy/foo


The way forward always starts with a minimal test.