Training, Open Source computer languages
PerlPHPPythonMySQLApache / TomcatTclRubyJavaC and C++LinuxCSS 
Search for:
Home Accessibility Courses Diary The Mouth Forum Resources Site Map About Us Contact
For 2023 - we are now fully retired from IT training.
We have made many, many friends over 25 years of teaching about Python, Tcl, Perl, PHP, Lua, Java, C and C++ - and MySQL, Linux and Solaris/SunOS too. Our training notes are now very much out of date, but due to upward compatability most of our examples remain operational and even relevant ad you are welcome to make us if them "as seen" and at your own risk.

Lisa and I (Graham) now live in what was our training centre in Melksham - happy to meet with former delegates here - but do check ahead before coming round. We are far from inactive - rather, enjoying the times that we are retired but still healthy enough in mind and body to be active!

I am also active in many other area and still look after a lot of web sites - you can find an index ((here))
stuck making a small change to a script

Posted by man_i_kin (man_i_kin), 12 April 2006
im not a perl man, at uni it was c and c++ but ive just been given a perl script to get working. ive made most of the changes and understand what it does but i cant quite get it to work. heres the script.

open(PFADMIN, $ARGV[0]) or die "Usage: perl <pfadmin output> <entryid output> <store name>\n";
open(ENTRYID, $ARGV[1]) or die "Usage: perl <pfadmin output> <entryid output> <store name>\n";

$storename = $ARGV[2];

##this can be modified depending on the profile naming scheme that is chosen.
$profile_name = $ARGV[2]._pr;

my @array;
my $index = 0;
my $curfolder;
my $props;

while (<PFADMIN>)
 if (/$storename/)
   $array[$index++] = $curfolder;
 } elsif (/^\S/) {
   $curfolder = $_;

while (<ENTRYID>)
 if (/Recognized/)
     ($trash1, $trash2, $trash3, $ptag) = split(' ');
     $props=$props.$ptag." ";
 ($foldername, $entryid) = split('\t');
 chomp $entryid;
 foreach $folder (@array)
   if ($folder=~/$foldername/)
     printf "createindex $profile_name $entryid 0x30070040 $props\n";
     $folder = "";

basically this script reads in two text files, compares them with a name entered and spits out a nice formatted line into a batch file.
the problem is that around line 37 it stops. it does work when the text file goes only one "/" deep but if it goes deeper its stuck.
an example would be:

it can process 2YH, but it fails when it gets to 2YH\2YHLOGSAL.
please help, im totally stuck trying to extend its scope!

Posted by admin (Graham Ellis), 12 April 2006
You talk about it being only "1 / deep" but then use \ in your example.  Which is it you're using?

The use of a / in $foldername is fine - it's just a character - but the use of a \ will cause you a problem as you're calling up a special sequence in your regular expression.

If you must have \ characters in $foldername, add the line
$foldername = quotemeta($foldername);
directly after the line in which the variable is set up.

Posted by man_i_kin (man_i_kin), 18 April 2006
Thanks for the reply, and i did make a mistake, its a "\" problem, not "/".
From what youve said would this look more suitable?
   if ($folder=~/$foldername/)
     $foldername = quotemeta($foldername);

So, from my understanding, the quotemeta will strip out everything but the alpanumeric characters. Is the issue with this script that is cant handle the "\"? And therefore by removing it the script should run?
Thanks for your help again, im slowly picking up the syntax!

Posted by admin (Graham Ellis), 18 April 2006
No, your change to add the quotemeta must be BEFORE the if statement in which you check it and not after.   There's no point in shutting the stable door after the horse has bolted!

Add it after the
($foldername, $entryid) = split('\t');

Posted by man_i_kin (man_i_kin), 19 April 2006
right, you have to excuse me, id say im just having a bad day but being overwhelmed by unknown programming languages always hurts!
and thank you for your help. works perfectly. Ive done a bit of reading up and from what i can see the problem was that it took the whole line as one and didnt recognise \ as a break in the line. is that correct?(ish)

Posted by admin (Graham Ellis), 20 April 2006
Correctish    ... any \x sequence where x is a letter or a digit in a regular expression (i.e. appears between slashes after an =~ operator) is taken as being a "special" - for example

\n - match a new line
\t - match a tab
\s - match a white space
\S - match a non-space
\x4A - match ASCII character 4A (hex)
\2 - match the second pattern from a previous capture.

If you REALLY want to match a \, you preceed it with another \ - in front of a character which is neither a letter nor a digit, \ means "I really want a ..." - thus \\ - I really want a \.

quotemeta adds extra \ characters to protect \ characters already in the string - so 8XM\8XMMLA becomes 8XM\\8XMMLA in your example, and so on.

This page is a thread posted to the opentalk forum at and archived here for reference. To jump to the archive index please follow this link.

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2023: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 793803 • EMAIL: • WEB: • SKYPE: wellho