Re: A perl question
On Tue, 2004-04-20 at 11:54, Bob Bell wrote: > $ perl -pe '$tag="MyTag";$other="MyOtherTag";s/::(\w+)/${$1}/ge;' <<< "foo ::tag > ::other" > foo MyTag MyOtherTag > > Key bit there is "/e". Worked perfect! Thanks Bob, and Jim, for the help. -- brian <[EMAIL PROTECTED]> ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: A perl question
Brian wrote: > Every s/ operation I come up with always ends up replacing ::tag with > the literal "$tag". Perl's DWIM features usually pick up a single variable in the replacement part and do the right thing, but you can add a 'e' modifier to the end of the substitution to cause perl to interpret the replacement part as an expression. You can even add additional 'e' modifiers to cause additional levels of evaluation, but I've never seen this usefully done for more than two levels. ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: A perl question
On Tue, Apr 20, 2004 at 11:47:06AM -0400, brian <[EMAIL PROTECTED]> wrote: On Tue, 2004-04-20 at 11:30, Bob Bell wrote: > Can you share code? I don't see why you'd have a problem. > > $ perl -pe '$tag="MyTag";s/::tag/$tag/g;' <<< "foo ::tag ::other" > foo MyTag ::other Sure... I think I didn't make the request totally clear anyway... $template_message =~ s/::(\w+)/\$$1/g; ## the above line is sort of what I am trying to accomplish. replace all double-colon words with the value of their equivalent variable Ah, got you now (I think so, at least -- I actually didn't ready very closely). $ perl -pe '$tag="MyTag";$other="MyOtherTag";s/::(\w+)/${$1}/ge;' <<< "foo ::tag ::other" foo MyTag MyOtherTag Key bit there is "/e". -- Bob Bell ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: A perl question
On Tue, 2004-04-20 at 11:30, Bob Bell wrote: > Can you share code? I don't see why you'd have a problem. > > $ perl -pe '$tag="MyTag";s/::tag/$tag/g;' <<< "foo ::tag ::other" > foo MyTag ::other Sure... I think I didn't make the request totally clear anyway... (BTW, this is part of a trouble ticketing system, in case that helps the mindset). Here are some relevant bits: &GetOrderData(cust_id); ## this line pulls about 50 variables from a data base linked to the row which matched cust_id. ## In this subroutine, if you are not opening a "trouble" ticket, then you must be using a ticket template... if ($subtype ne 'trouble') { ## we're basically pulling 2 items out of a template database to craft an email. ## subtype is defined elsewhere, which would be things like "spamalert", "circuitdown", etc... $sth = $dbh->prepare ( "select subject, message from TicketTemplate where menuItem = '$subtype'"); $sth->execute(); $sth->bind_columns(\$template_subj, \$template_message); $sth->fetch(); $sth->finish(); ## Okay, so now we have $template_subj and $template_message populated. $template_message contains these double-colon tags that I want to replace... $template_message =~ s/::(\w+)/\$$1/g; ## the above line is sort of what I am trying to accomplish. replace all double-colon words with the value of their equivalent variable $template_message =~ s/::company/$company/g; ## I could do that ^^ for each variable, but it's cumbersome, and as new variables are added I have to go back and update the code, and it seems kludgy to have 50 iterations of the above line. $sentdesc = $template_subj; $sentnotes = $template_message; } Here is an example: Our monitoring systems have reported a possible ::circuittype circuit down at the following location: ::address, ::city, ::state. If your connectivity appears to be down, please check the power status of the ::routerbrand ::routermodel and reboot it if possible. If you need assistance, you may reply to this ticket with light status or additional information. If we see the connection come back up we will automatically close the ticket. Thank you After running through this code block, the above template would become: Our monitoring systems have reported a possible DSL circuit down at the following location: 12345 Any Street, Your Town, FL. If your connectivity appears to be down, please check the power status of the Cisco 1601 and reboot it if possible. If you need assistance, you may reply to this ticket with light status or additional information. If we see the connection come back up we will automatically close the ticket. Thank you -- brian <[EMAIL PROTECTED]> ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
Re: A perl question
On Tue, Apr 20, 2004 at 11:20:54AM -0400, brian <[EMAIL PROTECTED]> wrote: > Every s/ operation I come up with always ends up replacing ::tag with > the literal "$tag". Can you share code? I don't see why you'd have a problem. $ perl -pe '$tag="MyTag";s/::tag/$tag/g;' <<< "foo ::tag ::other" foo MyTag ::other -- Bob Bell ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss
A perl question
Maybe someone can help? Okay, so I'm trying to do something in perl, a "sort of" mail merge kind of concept. I have a block of text, something like: "Blah blah blah blah ::company foo foo foo foo ::address" I also have a bunch of variables populated with data ($company, $address, $city, $state, $etc...) I want to replace the "::tag" in the text block with the value of the corresponding variable. Ie: if $tag="SomeText" everytime I find ::tag in the text block I want to remove ::tag and replace it with SomeText. Every s/ operation I come up with always ends up replacing ::tag with the literal "$tag". Anybody can maybe point me in the right direction? Thanks. -- brian <[EMAIL PROTECTED]> ___ gnhlug-discuss mailing list [EMAIL PROTECTED] http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss