Extracting text (Perl)

From ben.goodacre.name/tech

Jump to: navigation, search

The split() function gives cut functionality to Perl.
Usage: split('delimeter',input,max_no_of_fields);

Example

Cycle through the output of a find command and output the second dir and put them into the array @dirnames:

open(TIMELINE_PIPE,"find www/ -type f -name *.jp* -mtime 6|");
my $i=0;my @dirnames;
while (<TIMELINE_PIPE>) {
	chomp;
	my @dir1 = split('/',$_,3);
	my $dir2 = $name1[1];
	print "$dir2\n";
	push @dirnames, $dir2
}
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox