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
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:
index.cgi?n0=NAE&n1=12345678&NDBq=1>

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

to get:
NAE12345678NDBQ1.html>

(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:

Code:
# 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 www.opentalk.org.uk 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., 2014: Well House Manor • 48 Spa Road • Melksham, Wiltshire • United Kingdom • SN12 7NY
PH: 01144 1225 708225 • FAX: 01144 1225 899360 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho