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))
patterns in patterns

Posted by wilko (wilko), 29 January 2004
I am re-writing URLs in Perl to make them search engine friendly which is working well but I have a problem trying to figure the following:

I am re-writing:


to get:

(the > at the end is there to stop the pattern being greedy)

My problem
I want to replace $2 with $NDB[$2] where $2 is used to look up a value. The problem is that $NDB[X] has junk in it that needs to be removed using:
/(.*)##(.......)##(.*)/$2/    I only want the bit between the ##s

How can this pattern match be embedded into the first pattern making use of $2 from the first?

Help please!

Posted by admin (Graham Ellis), 29 January 2004
I think I would do it using several statements rather than just the one that would get over-complex. Something like:

# Get the two interesting bits out of the incoming string
($first,$second) = ($input =~ /index.cgi\?n0=NAE&n1=([0-9]*)&NDBq=([0-9]{1})>/);
# Do the lookup based on $second
($two_a) = ($NDB[$second] =~ /##(.*)##/);
# and make up your result
$output = "NAE${first}NDBQ${two_a}.html>";

Posted by wilko (wilko), 29 January 2004
Sorry I omitted to say that I am replacing multiple occurrences of the pattern within the input variable. This is why I was trying to get a solution that does it all in one hit.

$input =~ s/index.cgi\?n0=NAE&n1=([0-9]*)&NDBq=([0-9]{1})>/NAE$1NDBQ$2.html>/g;

where $2 is the second pattern match

It's got me foxed!

BTW. This is a bit OT - I see you have a mixture of platforms in your office so wondered if you had any ideas how I can print from an OS9 Mac via ethernet to a non PostScript laser.

Posted by admin (Graham Ellis), 30 January 2004
I still think I would do it in two steps - simply put the whole thing into  while loop with a global flag; let me know if you would like me to post a sample or if this is sufficient guidance (I'm too jetlagged to write code tonight. Long flight, longer story of a failed aircraft ...)

On the OS9 / Ethernet / Printer / non-postscript, we have examined the deep recesses of Lisa's memory ... the conclusion is that the viatl words are "non-postscript";  you would need a specific driver for the particular printer under OS9 - that's not the case for postscript, as there's a generic postscript driver in OS9.

Posted by wilko (wilko), 2 February 2004
Thanks for that, I'll figure out the code.

As for printing across a network to a non PS printer from a Mac, it seems that it's not that straightforward but I have found a product called Power Print for Networks. It's half software and half hardware. What I have at the moment is an old iMac sharing it's USB printer port which is working fine. When I stop resisting moving to OSX all these problems should go away!

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