> I am trying to extract ".jpg" (subtype of the file) from the string:
> c:\my_files\file.jpg
>
> I found the following pattern on the net:
> $file =~ s/.*[\/\\](.*)/$1/;
> which extracts the file name (file.jpg). I understood most of that pattern
> except what does the (.*) part does? And how can I tweak it so I only get
> the "jpg" part.

(.*) breaks down into 3 things:
the parens () say to capture whatever is matched by the regexp inside to $1
(or $2, etc)
the . says match any character
the * says to match 0 or more of the previous character

so, (.*) says to capture 0 or more of any character to $1.


You are using s///, so the contents of $file are being changed to the
contents of $1, this
may not be what you really want to do, if you're going to use the contents
of $file later.


read "perldoc perlre" for more information


If you want to capture ".jpg" use:
 $file =~ s/.*[\/\\].*(\..*)/$1/;

If you just want "jpg" use:
 $file =~ s/.*[\/\\].*\.(.*)/$1/;

                                /\/\ark


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to