Regex Tricks


Beginning | Previous | Next

Below is a list of "tricks" that might come in useful:

Get the filename from a full path (on UNIX or MS-Windows):

$full_path = '/home/khamsi/.bashrc'; # set $full_path to something $full_path =~ m!([^/]*)$!; # use "!" char as delimiter, not "/" $filename = $1; print "$filename\n";

prints ".bashrc".

Remove the first column from any file:

perl -pi.bak -e 's/^.//' FILE Prompt user for answer and don't leave them alone until they give the correct response: do { print 'Enter yes to proceed, Bozo > '; chomp ($ans = <STDIN>); } while ($ans !~ /^y(es)?$/i) Get ith element from an array (not a regex trick, but cool just the same): $middle_name = (&get_full_$name)[$i]; Beginning | Previous | Next
Last Modified: $Date: 1997/09/18 09:14:29 $