[22791] in Perl-Users-Digest
Perl-Users Digest, Issue: 5012 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 20 14:06:07 2003
Date: Tue, 20 May 2003 11:05:16 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 20 May 2003 Volume: 10 Number: 5012
Today's topics:
Re: $ sign in a numeric <simon.andrews@bbsrc.ac.uk>
advice re perl modules <maxw@sgi.com>
Re: Array and html template <nospam@raytheon.com>
Re: Best way to compare binary files? ctcgag@hotmail.com
Close html page <chris_12003@yahoo.com>
Re: Combining lines of a text file <nospam@raytheon.com>
Re: Combining lines of a text file <nobody@dev.null>
Re: Combining lines of a text file <nobody@dev.null>
copying files between two directories (Naina)
Re: Exporter not doing what I expect <michael.p.broida@boeing.com>
Re: Exporter not doing what I expect <noreply@gunnar.cc>
Get file extensions by regular expression <Rene.Scheibe@gmx.net>
Re: Get file extensions by regular expression (Helgi Briem)
Re: Get file extensions by regular expression <steve@uptime.orgNo.ukSpam>
Re: Get file extensions by regular expression <goedicke@goedsole.com>
Re: Inserting a record into a table using a value from (Tad McClellan)
Re: multiple sorts on an array <jvs+nospam@india.ti.com>
Re: newbie needs help please <n_joeller@sharblbaziilyar.com>
Re: newbie needs help please <nobody@dev.null>
Re: newbie needs help please (Helgi Briem)
Re: newbie needs help please <g4rry_short@zw4llet.com>
Re: newbie needs help please (Tad McClellan)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 20 May 2003 16:05:49 +0100
From: Simon Andrews <simon.andrews@bbsrc.ac.uk>
Subject: Re: $ sign in a numeric
Message-Id: <3ECA444D.6060302@bbsrc.ac.uk>
Kevin wrote:
> how do i check and strip off a dollar sign '$' in a
> numeric field.
>
> thanks
>
> kg
my $number = '$2.50';
$number =~ tr/$//d;
print "$number\n";
or if you want to be slightly more specific and only strip off a leading
$ sign...
my $number = '$2.50';
$number =~ s/^\$//;
print "$number\n";
------------------------------
Date: Tue, 20 May 2003 09:26:31 -0700
From: Max Waterman <maxw@sgi.com>
Subject: advice re perl modules
Message-Id: <badl1c$1l17hp$1@fido.engr.sgi.com>
Hi,
I have developed a perl application on one machine which has perl v5.6.1,
and I have used CPAN.pm to install the require modules.
I now need to install the application on another machine which has either
perl 5.004_05 or 5.004_02, but is missing a fair number of the perl
modules my application needs.
I can install perl modules, but I should not update any that are already
installed since other applications rely on them.
I would like to be able to create a self contained application so that it
doesn't break when someone changes the machine's perl installation. I
guess this is the same as if I had no root privs at all.
Can someone tell me how I can do this?
If it were a binary application, I would use 'ldd' and 'rld' to locate
the libs the app uses, and copy them into a local directory, etc etc. Not
sure even how to find out what the full path of a perl module my app
'use's let alone make sure the app uses local ones.
Thanks.
Max.
------------------------------
Date: Tue, 20 May 2003 10:11:01 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Array and html template
Message-Id: <Vzrya.3329$c6.3249@bos-service2.ext.raytheon.com>
Blnukem wrote:
> Hi All
>
> I need some help I'm opening a text file and putting text information into
> @data
> Then I'm opening a remote html template file in text format that looks like
> this
>
> <html>
> <head>
> @data
> </body>
> </html>
>
> When I print to file it print out "@data" instead of the information that is
> contained within the @data array
> So my Perl question is how do I get @data into the template.
>
>
> <snipped>
>
> # Open the database with the page data
> open (PAGE, "</pages/page.dat")|| &Error('open','file');
> @data = <PAGE>;
> close(PAGE);
>
> # Get the template of the site
> open (TEMPLATE, "</templates/template.dat")|| &Error('open','file');
> @template = <TEMPLATE>;
> close(TEMPLATE);
>
> # Sart building webpage
> open (NEWPAGE, ">/testpage/page.htm")|| &Error('open','file');
> flock(NEWPAGE, 2);
>
> print NEWPAGE "@template";
>
> flock(NEWPAGE, 8);
> close(NEWPAGE);
>
> Thanx in advance Blnukem
>
>
Aside from what you've already been offered, I guess the simplest way
that strikes me using your present "strategy" is to eval() each line in
your template before printing it to the new output file:
##++
## chomp( @template ); recommended.
##
## Me hopes you also realize "/testpage/page.html" is writing to
## the "root" of your filesystem and not to the root of your WWW
## server. If you are on Windoze... this isn't the way to write it.
open( NEWPAGE, ">/testpage/page.html" ) || die "open: $!";
foreach (@template) { print NEWPAGE eval( $_ ) . "\n" }
close( NEWPAGE );
##--
Also note in your own "template" file, you have no closing <head> tag
(eg. </head>) and no opening <body> tag, so your HTML would be malformed
and depending on the browser may or may not display as you would expect
or like. (Unless the closing <head> tag and opening <body> tag is in
your DATA, which then would cause me to REALLY question what in the
world you are trying to do because at first look it would appear you are
simply trying to wrap existing [text?] file data contents in HTML and
display it in HTML. There are existing systems for this too, by the
way, that will save you a lot of work...)
As previously indicated, there are already really good templating
systems out there, so why not use one that's tried and true? I
recommend HTML::Template or Template Toolkit for what you are attempting
to do. Template Toolkit would be a bit of overkill for this;
HTML::Template would do nicely. It let's Perl be Perl and HTML be HTML
about as nicely as anything.
Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN
email: olivec(AT)indy(DOT)raytheon(DOT)com
------------------------------
Date: 20 May 2003 15:05:33 GMT
From: ctcgag@hotmail.com
Subject: Re: Best way to compare binary files?
Message-Id: <20030520110533.496$hp@newsreader.com>
"Ben Kennedy" <bkennedy@hmsonline.com> wrote:
>
> An alternative to comparing bytes would be to compare a message digest of
> your two files, for example with Digest::MD5 - this will tell you 100% of
> the time if two files are different (that is, different checksums always
> indicate different files). There is an incredibly slight chance two
> different files will come out with the same checksum, but I think most
> would consider the risk of that happening to be statistically
> insignifigant.
It's not clear what the null hypothesis is, but as you can draw
as large a sample as you wish to, you can achieve any desired level
of statistical significance. The real question is, is it practically
significant?
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service New Rate! $9.95/Month 50GB
------------------------------
Date: Tue, 20 May 2003 10:46:39 -0700
From: "Chris" <chris_12003@yahoo.com>
Subject: Close html page
Message-Id: <vckqfvmofm9k33@corp.supernews.com>
I have the following in my code to begin my html page
print "Content-type: text/html\n";
Is there another statement I can use that'll close the page so that I can
issue another print "Content..., actually I need to send a cookie header
later in my code and it isn't working because the header was already sent.
Thanks,
Chris
------------------------------
Date: Tue, 20 May 2003 10:27:56 -0500
From: Chris Olive <nospam@raytheon.com>
Subject: Re: Combining lines of a text file
Message-Id: <LPrya.3332$c6.3089@bos-service2.ext.raytheon.com>
slack3r wrote:
> Given the following sample, delimited, text file:
>
> 01721 ;CLI ;PAD,DESK,REFILL,15.5X21,PLN ; 4
> 14160 ;UNVSL ;FOLDER,HANG,3.5,LTR,GN ; 1
> 14160 ;UNVSL ;FOLDER,HANG,3.5,LTR,GN ; 1
> 01721 ;CLI ;PAD,DESK,REFILL,15.5X21,PLN ; 4
>
> Could anyone give me a hint on how to combine the like items (1st and
> 4th, 2nd and 3rd) into a new text file so the line only shows once
> with the total of the last column? I have a feeling I'm missing
> something simple but I just can't wrap my head around it (I'm new).
>
> Any help is greatly appreciated!
#!/usr/bin/perl -w
$|++;
while (<>) {
chomp;
($cat, $i) = (split( /;/ ))[1,-1];
$h{$cat} += int $i;
}
for (sort keys %h) { print "$_: $h{$_}\n" }
__END__
Call using a shell redirect: $ sample.pl < data.file
Chris
-----
Chris Olive
Systems Consultant
Raytheon Technical Services Corporation
Indianapolis, IN
email: olivec(AT)indy(DOT)raytheon(DOT)com
------------------------------
Date: Tue, 20 May 2003 16:28:12 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Combining lines of a text file
Message-Id: <3ECA5719.9040104@dev.null>
Helgi Briem wrote:
> On Tue, 20 May 2003 09:58:03 -0400, slack3r
> <slack3r@nowhere.com> wrote:
>
>
>>Given the following sample, delimited, text file:
>[...]
>>
>>Could anyone give me a hint on how to combine the like items (1st and
>>4th, 2nd and 3rd) into a new text file so the line only shows once
>>with the total of the last column?
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>[...]
> Open a command prompt window and type:
>
> perldoc -q duplicate
>
> and you will be taught all about how to remove
> duplicate elements in a list.
Except that's not quite what the OP wants, is it?
------------------------------
Date: Tue, 20 May 2003 16:56:25 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: Combining lines of a text file
Message-Id: <3ECA5DB4.4000802@dev.null>
slack3r wrote:
> Given the following sample, delimited, text file:
>
> 01721 ;CLI ;PAD,DESK,REFILL,15.5X21,PLN ; 4
> 14160 ;UNVSL ;FOLDER,HANG,3.5,LTR,GN ; 1
> 14160 ;UNVSL ;FOLDER,HANG,3.5,LTR,GN ; 1
> 01721 ;CLI ;PAD,DESK,REFILL,15.5X21,PLN ; 4
>
> Could anyone give me a hint on how to combine the like items (1st and
> 4th, 2nd and 3rd) into a new text file so the line only shows once
> with the total of the last column? I have a feeling I'm missing
> something simple but I just can't wrap my head around it (I'm new).
>
> Any help is greatly appreciated!
>
use strict;
#We'll keep our results in...
my %results;
while (<DATA>){
#First, let's split your lines on the last semicolon
my ($key, $value)=($1, $2) if m/(.*);([^;]+)$/;
#Then add them to the tally:
$results{$key}+=$value;
};
#We are done; let's see the results;
print join "\n", map{"$_: $results{$_}"}(keys %results);
__DATA__
01721 ;CLI ;PAD,DESK,REFILL,15.5X21,PLN ; 14
14160 ;UNVSL ;FOLDER,HANG,3.5,LTR,GN ; 31
14160 ;UNVSL ;FOLDER,HANG,3.5,LTR,GN ; 16
01721 ;CLI ;PAD,DESK,REFILL,15.5X21,PLN ; 24
------------------------------
Date: 20 May 2003 10:44:09 -0700
From: naina_r@yahoo.com (Naina)
Subject: copying files between two directories
Message-Id: <5622768f.0305200944.6b260565@posting.google.com>
Hi,
Iam trying to copy files existing under two different root
directories.Help needed with also if any Attributes can be used to
get all files with some extension. Any suggestions would be welcome.
Thanks,
Naina
------------------------------
Date: Tue, 20 May 2003 16:57:05 GMT
From: "Michael P. Broida" <michael.p.broida@boeing.com>
Subject: Re: Exporter not doing what I expect
Message-Id: <3ECA5E61.6F5783D@boeing.com>
Gunnar Hjalmarsson wrote:
>
> Michael P. Broida wrote:
> > Gunnar Hjalmarsson wrote:
> >> "our" is _shorter_ than "use vars"...
> >>
> >> If you want your program to be able to be run with Perl versions
> >> older than 5.6.0, you _must_ use "use vars". I always use "use
> >> vars" as soon as portability is an issue.
> >
> > I'm on Perl 5.6.0 here, and I don't think this tool will ever go to
> > an OLDER Perl. But ya just never know...
> >
> > As long as "shorter" is the only real advantage (assuming you mean
> > only "fewer characters to type"), I will probably just stick with
> > "use vars" for that particular item.
>
> Well, that is what I mean, and that is the only difference I'm aware
> of (which doesn't guarantee that there isn't anything else...). Maybe
> somebody can fill in here.
>
> > I think I do need to use "our" for the Exporter variables, though.
>
> No, you don't. You can do
>
> use vars qw($VarONE $VarTWO);
>
> or
>
> use vars '$VarONE', '$VarTWO';
Oops, by "the Exporter variables" in this case, I meant
the @ISA, @EXPORT, and @EXPORT_OK variables. It just
wouldn't work until I changed those to "our" variables.
Mike
------------------------------
Date: Tue, 20 May 2003 19:57:10 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Exporter not doing what I expect
Message-Id: <badqdm$sfl0h$1@ID-184292.news.dfncis.de>
Michael P. Broida wrote:
> Gunnar Hjalmarsson wrote:
>>Michael P. Broida wrote:
>>>I think I do need to use "our" for the Exporter variables, though.
>>
>>No, you don't. You can do
>>
>> use vars qw($VarONE $VarTWO);
>>
>>or
>>
>> use vars '$VarONE', '$VarTWO';
>
> Oops, by "the Exporter variables" in this case, I meant
> the @ISA, @EXPORT, and @EXPORT_OK variables. It just
> wouldn't work until I changed those to "our" variables.
Yes it would. Same thing:
use vars qw(@ISA @EXPORT @EXPORT_OK);
@ISA = qw(Exporter);
@EXPORT = qw(...);
@EXPORT_OK = qw(...);
/ Gunnar
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Tue, 20 May 2003 17:37:10 +0200
From: "Rene Scheibe" <Rene.Scheibe@gmx.net>
Subject: Get file extensions by regular expression
Message-Id: <badi35$s2leb$1@ID-65612.news.dfncis.de>
common problem:
i have a filename and want to get its extension.
my sugestions was:
($extension) = ($filename =~ /\.([^\./]+)$/);
so it grabs me everything after a period in the filename
that doesn't include another period or slash.
but i get a parsing error.
can you give me some advice? (am real new to perl)
rene
------------------------------
Date: Tue, 20 May 2003 15:51:33 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Get file extensions by regular expression
Message-Id: <3eca4ee1.3459663312@news.cis.dfn.de>
On Tue, 20 May 2003 17:37:10 +0200, "Rene Scheibe"
<Rene.Scheibe@gmx.net> wrote:
>i have a filename and want to get its extension.
>my sugestions was:
>
>($extension) = ($filename =~ /\.([^\./]+)$/);
>
>so it grabs me everything after a period in the filename
>that doesn't include another period or slash.
>
>but i get a parsing error.
Here's one way:
my ($filename,$extension) = /(.*)\.(.*)$/;
--
Regards, Helgi Briem
helgi DOT briem AT decode DOT is
------------------------------
Date: Tue, 20 May 2003 17:02:08 +0100
From: Stephen Hildrey <steve@uptime.orgNo.ukSpam>
Subject: Re: Get file extensions by regular expression
Message-Id: <1053446528.70926.0@iapetus.uk.clara.net>
In article <badi35$s2leb$1@ID-65612.news.dfncis.de>, Rene Scheibe wrote:
> common problem:
>
> i have a filename and want to get its extension.
> my sugestions was:
>
> ($extension) = ($filename =~ /\.([^\./]+)$/);
>
> so it grabs me everything after a period in the filename
> that doesn't include another period or slash.
>
> but i get a parsing error.
That's because you're using the match delimiter in the character class,
something like this would work:
($extension) = ($filename =~ m{\.([^\./]+)$});
It's more efficient in this case to use a split though, something like
the following will do the trick:
@bits = split(/\./);
$ext = $bits[$#bits];
On this system, running Perl 5.6.1, the split method runs in 0.75 of the
time (testing on 100,000 iterations).
Regards,
Steve
------------------------------
Date: Tue, 20 May 2003 16:25:10 GMT
From: William Goedicke <goedicke@goedsole.com>
Subject: Re: Get file extensions by regular expression
Message-Id: <m38yt18u1u.fsf@mail.goedsole.com>
Dear Rene -
"Rene Scheibe" <Rene.Scheibe@gmx.net> writes:
> i have a filename and want to get its extension.
I think I'd use split. Here's some untested code.
@fn_pieces = split "\.", $fn;
$extension = $fn_pieces[-1];
Yours - Billy
============================================================
William Goedicke goedicke@goedsole.com
http://www.goedsole.com:8080
============================================================
Lest we forget:
Common things are common. In fact, very unusual examples
of common things are much more common than rare things.
- William S. Craig M.D.
------------------------------
Date: Tue, 20 May 2003 11:59:13 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Inserting a record into a table using a value from a sequence
Message-Id: <slrnbcknn1.2lc.tadmc@magna.augustmail.com>
ctcgag@hotmail.com <ctcgag@hotmail.com> wrote:
> uma@bluemartini.com (Uma Mahesh) wrote:
>> Any help or pointers are appreciated.
pointer 0)
http://mail.augustmail.com/~tadmc/clpmisc.shtml
> pointer 1) post some code that causes the error.
make a short (less than 20-30 lines) and *complete* program
that illustrates the problem you are having.
> pointer 2) post the actual error message.
Show the output (including the verbatim text of any messages) of
your program.
> pointer 3) but not necessarily to a perl group, if the question is
> about databases and not perl.
Question should be about Perl, not about the application area
It can be difficult to separate out where your problem really is,
but you should make a conscious effort to post to the most
applicable newsgroup. That is, after all, where you are the most
likely to find the people who know how to answer your question.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 20 May 2003 15:04:58 GMT
From: Jahagirdar Vijayvithal S <jvs+nospam@india.ti.com>
Subject: Re: multiple sorts on an array
Message-Id: <badg6q$g5e$1@home.itg.ti.com>
* Janek Schleicher <bigj@kamelfreund.de>:
>
> I have not looked at the code, as I don't understand your question.
> Your given input is exactly the same as the given sorted output ?!
Opps! sorry
here's a proper example the actual list is long (100's of elements)
the user is expected to interactively enter a sort pattern
evaluate the output and give the next sort pattern so the expected
response will be
@array= ("foo", "bapr", "bar1", "foo22", "baz", "bazar", "egg", "foo1", "egg1", "bar2" )
USER: foo
@array= ("foo", "foo1", "foo22", "egg", "egg1", "bar2", "bazar", "bapr", "baz", "bar1")
USER: ba\\w*r
expected: @array=("bar2", "bapr", "bar1", "bazar", "foo", "foo1", "foo22", "egg", "egg1", "baz")
actual: @array= ("bapr", "bazar", "bar2", "bar1", "baz", "egg1", "foo22", "foo1", "foo", "egg")
giving the second regular expression messes up the initial sorted
part(*foo*) in the actual case it distributed them to different
locations in the array the sort function used is
sort { $return_val=+1;if ($a=~ /$sortpattern/){ $return_val-=2 } if
($b =~ /$sortpattern/){ $return_val+=1; } return $return_val;} @array
I managed to do this using grep to detect and delete matching elements
after moving them to another array but was wondering wether there would
be a simple way to do it using sort and a single array
Regards
Jahagirdar Vijayvithal S
--
Life without danger is a waste of oxygen.
Jahagirdar .V.S
IC Design Engineer , Texas Instruments (India) Ltd.
91-80-5099129(O)
------------------------------
Date: Tue, 20 May 2003 15:08:17 GMT
From: Noerd <n_joeller@sharblbaziilyar.com>
Subject: Re: newbie needs help please
Message-Id: <3ECA44D2.AB4B273@sharblbaziilyar.com>
Tad McClellan wrote:
> Noerd <n_joeller@sharblbaziilyar.com> wrote:
>
> > My Perl script successfully "fixes up" book descriptions from a list. It
> > works great
>
> So we are not looking at your real code then?
>
> The code you posted does not "work great"...
>
> > Currently, if a title of a book is "Wonderful Book (P)," my snippet of
> > code will transform it to "Wonderful Book (papercover)."
> >
> > if the book title does NOT contain "(P)" I want the word
> > "(hardbound)" added.
>
> > Here is the code I am using.
>
> I doubt that...
>
> > s/\(P\\\)/(papercover)/, // if title contains "(P)", replace with
> ^^
> ^^ what's that for?
>
> > "papercover"
>
> if title contains "(P\)", replace with "papercover"
>
> > ### I want the result to be: "My Life Story (hardbound)"
>
> s/$/ (hardbound)/ unless s/\(P\)/(papercover)/;
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
As I stated in my original post, it is a *snippet* of code. And, it works
perfectly, because it interfaces with mysql. A previous portion of my code
adds slashes (escapes) via "quotemeta" and some other code I've used. My
question should be answered on the premise that "my code works perfectly,
except a small adjustment is needed. If such adjustment is needed, what
alteration to the existing code must happen to make the required small
adjustment." Okay Tad?
------------------------------
Date: Tue, 20 May 2003 15:20:48 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: newbie needs help please
Message-Id: <3ECA4748.1060104@dev.null>
Noerd wrote:
>[...]
> if I have 2 book titles:
> "Wonderful Life (P)"
> "My Life Story"
> ...I would like my code to do the following:
> "Wonderful Life (papercover)" //my code already does this
> "My Life Story (hardbound)" //this is what I can't figure out how to do
>
> Here is the code I am using.
This is *not* the code you are using. The code you retyped here is full
of syntax errors. If you want to show us code, cut and paste working code.
> What can I do to the following code to make
> this happen???
> ### for example, $bookDescription[2] is "My Life Story"
> $_ = lc, // makes title lowercase
> s/\b(\w)/\u$1/g, // capitalizes
> s/('S|\bOf| And| The)\b/\L$1/g, //makes "of" "and" etc. lowercase
Oh, yeah? How about "Of Mice and Men?"
> s/\(P\\\)/(papercover)/, // if title contains "(P)", replace with
> "papercover"
> for $bookDescription[2];
> ### I want the result to be: "My Life Story (hardbound)"
>
Try something like...
my $paperback_symbol='\(P\)';
my @books=( 'Of Mice and Men',
'Programming Perl (P)',
'the collected poems of ee cummings'
);
for (@books){
$_ = lc;
s/\b(\w)/\u$1/g;
s/('S|\bOf| And| The)\b/\L$1/g;
$_=$_.' (hardbound)' unless m/$paperback_symbol/;
s/$paperback_symbol/(papercover)/;
}
print join"\n", @books;
__END__
Which prints
of Mice and Men (hardbound)
Programming Perl (papercover)
The Collected Poems of Ee Cummings (hardbound)
------------------------------
Date: Tue, 20 May 2003 15:22:15 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: newbie needs help please
Message-Id: <3eca472b.3457688603@news.cis.dfn.de>
On Tue, 20 May 2003 15:08:17 GMT, Noerd
<n_joeller@sharblbaziilyar.com> wrote:
>Tad McClellan wrote:
>> The code you posted does not "work great"...
>As I stated in my original post, it is a *snippet* of code. And, it works
>perfectly, because it interfaces with mysql. A previous portion of my code
>adds slashes (escapes) via "quotemeta" and some other code I've used. My
>question should be answered on the premise that "my code works perfectly,
>except a small adjustment is needed. If such adjustment is needed, what
>alteration to the existing code must happen to make the required small
>adjustment." Okay Tad?
But you are making completely unneccessary demands
on the responder's time by not including your actual
real life code. The tester has to retype your
code, fix the mistakes, guess at extra code that
needs to come before it and so on before even
beginning to answer the question.
Tad has the patience of a saint. Most of us just
ignored your post completely because it was just
to much work to get it to work properly.
You should thank your lucky stars there are people
like him out there who put up with you and take
the time out of their busy day to help for no reward
except rudeness.
--
Regards, Helgi Briem
helgi DOT briem AT decode DOT is
------------------------------
Date: Tue, 20 May 2003 17:29:41 +0000
From: Garry Short <g4rry_short@zw4llet.com>
Subject: Re: newbie needs help please
Message-Id: <badl95$rdf$1$8300dec7@news.demon.co.uk>
Noerd wrote:
> Thank you in advance. I have a question about something new I learned in
> this group.
>
> My Perl script successfully "fixes up" book descriptions from a list. It
> works great and I'd like to continue using the following snippet of
> code.
>
> Currently, if a title of a book is "Wonderful Book (P)," my snippet of
> code will transform it to "Wonderful Book (papercover)."
>
> However, I'd like to make the following small change to my existing
> code: if the book title does NOT contain "(P)" I want the word
> "(hardbound)" added. For example, if the title of the book is,
> "Wonderful Book," I want my snippet of code to transform it to
> "Wonderful Book (hardbound)."
>
> To further clarify, if I have 2 book titles:
> "Wonderful Life (P)"
> "My Life Story"
> ...I would like my code to do the following:
> "Wonderful Life (papercover)" //my code already does this
> "My Life Story (hardbound)" //this is what I can't figure out how to do
>
> Here is the code I am using. What can I do to the following code to make
> this happen???
> ### for example, $bookDescription[2] is "My Life Story"
> $_ = lc, // makes title lowercase
> s/\b(\w)/\u$1/g, // capitalizes
> s/('S|\bOf| And| The)\b/\L$1/g, //makes "of" "and" etc. lowercase
> s/\(P\\\)/(papercover)/, // if title contains "(P)", replace with
> "papercover"
> for $bookDescription[2];
> ### I want the result to be: "My Life Story (hardbound)"
how about something like:
# Assume $_ = title of book
unless (s/\(P\)/\(papercover\)/) { $_ .= " (hardbound)"; }
# i.e. if the papercover substitution fails, then append " (hardbound)".
Not tried it, but it should work.
Regards,
Garry
------------------------------
Date: Tue, 20 May 2003 12:26:09 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie needs help please
Message-Id: <slrnbckp9h.2lc.tadmc@magna.augustmail.com>
Noerd <n_joeller@sharblbaziilyar.com> wrote:
> Tad McClellan wrote:
>> Noerd <n_joeller@sharblbaziilyar.com> wrote:
>> > Here is the code I am using.
>>
>> I doubt that...
>>
>> > s/\(P\\\)/(papercover)/, // if title contains "(P)", replace with
>> ^^
>> ^^ what's that for?
Apparently, it is "for" some mysql tool to eat before passing
s/\(P\)/(papercover)/
to Real Perl.
We were expected to already know that somehow?
>> if title contains "(P\)", replace with "papercover"
>>
>> > ### I want the result to be: "My Life Story (hardbound)"
>>
>> s/$/ (hardbound)/ unless s/\(P\)/(papercover)/;
[snip quoted .sig]
> As I stated in my original post, it is a *snippet* of code.
It is presumed to be Perl code when it is posted to the Perl newsgroup.
If it is not really Perl code, then you need to tell us, else the
answer may contain Perl constructs that are not available in
whatever unnamed "restricted Perl" it is that you are using.
> And, it works
> perfectly, because it interfaces with mysql. A previous portion of my code
> adds slashes (escapes) via "quotemeta"
So then the pattern that the regex engine ends up seeing is really
s/(P\)/(papercover)/
like before the quotemeta() ?
(that wouldn't "work" either.)
We have to know which backslashes "count" if we are to correctly
analyse what the pattern will match.
> My
> question should be answered on the premise that "my code works perfectly,
> except a small adjustment is needed.
To evaluate the behavior of a pattern match we *must* know what
pattern the regex engine is operating on.
We can be expected to understand what all of the punctuation characters
mean when it is Perl code.
We cannot be expected to understand what all of the punctuation characters
mean when it is not Perl code. In that case, you would need to tell us
what they mean, and mention that it is Not Really Perl in the first place.
You did neither. (You've done it before, this last January for example)
The pattern you posted did not match the text that you claimed
it would match, so I pointed that out. Correcting mistakes is
what happens here in clp.misc.
> If such adjustment is needed, what
> alteration to the existing code must happen to make the required small
> adjustment."
I provided just such an adjustment, did I not?
> Okay Tad?
I answered the question that was asked.
Okay Noerd?
You've now used up all of your coupons.
*plonk*
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 5012
***************************************