Click to See Complete Forum and Search --> : Regular Expressions in Perl


SuperHornet
12-07-2002, 06:34 PM
This script use's "find" to display the files path and filesize.

17201 winecheck
4096 xchat-xmms-0.7
6111 xchat-xmms-0.7/Artistic
2303 xchat-xmms-0.7/README
35349 xchat-xmms-0.7/xchat-xmms.pl
32 xchat-xmms-0.7/Xmms-Perl-0.12.tar.gz
119 xchat-xmms-0.7/DEADJOE
13322 xchat-xmms-0.7.tar.gz

what I am having trouble with, is stripping the filesize off and moving it into a array.
It always displays the size and file like it didnt do anything.

Maybe you can suggest something?

#!/usr/bin/perl -w

@search=`find * -printf %s" " -print`;
foreach $search (@search) {
$search =~ /([0-9])\b/;
push(@size , $search);
}
print @size;

with.a.twist
12-07-2002, 11:17 PM
Originally posted by SuperHornet

#!/usr/bin/perl -w

@search=`find * -printf %s" " -print`;
foreach $search (@search) {
$search =~ /([0-9])\b/;
push(@size , $search);
}
print @size;



If you use the "split" function on your array member $search it will make another array that can be parsed.

so you would not use the regular expression, but use split.

example:
@tempArray = split($search);
$filesize=$tempArray[1];
$fileBlahBlah=$tempArray[2];
$file_etc=$tempArray[3];


Check out the syntax for split. It will save you light years of time.

Good luck![COLOR=royalblue]

SuperHornet
12-08-2002, 11:23 AM
Thanks for the help there.
That worked nicely.

with.a.twist
12-08-2002, 02:45 PM
Glad I could help ( a little...).

iDxMan
12-23-2002, 03:40 PM
...and if you really wanted to use a regex:


($size, $file) = $search =~ /^(\d+)\s*(.+)/;


-r