It was Monday, July 28, 2003 when Joe Echavarria took the soap
box, saying:
:
:
:   Hi there,
:
:      What perl function can i use to extract a sub-string from a
:      string.
:
:
:       I have "myfile.txt", and i only want to print "myfile" to the
:       screen , how can i do it ?

If you would like low-level functions, consider using substr()
and index().

  perldoc -f substr perldoc -f index

Also, consider using regular expressions. You can use them in like
this example.

  my ($base) = ( $file =~ /^([^.]+)\./ );

That will capture everything from the beginning of the string to the
character before the first period, returning it in list context. This
stuffs the base of the filename into $base.

  perldoc perlre perldoc perlop

Finally, I would use File::Basename which provides a handy,
cross-platform compatible function for such maneuvers.

  perldoc File::Basename

Enjoy!

  Casey West

-- 
Shooting yourself in the foot with Apple System 7 
Double click the gun icon and a window giving a selection for guns,
target areas, plus balloon help with medical remedies, and assorted
sound effects. Click "shoot" button and a small bomb appears with note
"Error of Type 1 has occurred." 


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

Reply via email to