[22789] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5010 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 20 11:05:59 2003

Date: Tue, 20 May 2003 08:05:15 -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: 5010

Today's topics:
        $ sign in a numeric (Kevin)
    Re: $ sign in a numeric (Tad McClellan)
        =?ISO-8859-1?Q?removing_a_word_using_a_regexp_doesn't_w (Leif Wessman)
        Array and html template <blnukem@hotmail.com>
    Re: Array and html template (Tad McClellan)
        awstats ignores HostAliases if using %virtualname (gooze)
        Best way to compare binary files? <je@brighton.ac.uk>
    Re: Best way to compare binary files? (Anno Siegel)
    Re: Best way to compare binary files? (Randal L. Schwartz)
    Re: Best way to compare binary files? (Anno Siegel)
    Re: Best way to compare binary files? <jurgenex@hotmail.com>
    Re: Best way to compare binary files? (Helgi Briem)
    Re: Best way to compare binary files? <bkennedy@hmsonline.com>
    Re: can fork() be an alternative to while (1)? <ah@siol.net>
        Children killing parent SIGCHLD <tp601553@cia.gov>
        Combining lines of a text file <slack3r@nowhere.com>
    Re: Combining lines of a text file (Helgi Briem)
    Re: Inserting a record into a table using a value from  (Tad McClellan)
    Re: Inserting a record into a table using a value from  ctcgag@hotmail.com
    Re: making scalar variables from array elements, put in (bryan)
    Re: Memory problem (Anno Siegel)
        newbie needs help please <n_joeller@sharblbaziilyar.com>
    Re: newbie needs help please <john.thetenant-s@moving-picture.com>
    Re: newbie needs help please (Tad McClellan)
    Re: PHP or Perl ? <R-Yrreg@wiu.edu>
    Re: removing a word using a regexp doesn't w ork with t <bernard.el-hagin@DODGE_THISlido-tech.net>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 20 May 2003 07:13:07 -0700
From: kgiles@optonline.net (Kevin)
Subject: $ sign in a numeric
Message-Id: <337213e2.0305200613.42d95763@posting.google.com>

how do i check and strip off a dollar sign '$' in a 
numeric field.

thanks

kg


------------------------------

Date: Tue, 20 May 2003 09:52:51 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: $ sign in a numeric
Message-Id: <slrnbckga3.2fm.tadmc@magna.augustmail.com>

Kevin <kgiles@optonline.net> wrote:

> how do i check and strip off a dollar sign '$' 


   tr/$//d;


> in a 
> numeric field.


What is a "numeric field"?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 20 May 2003 06:45:19 -0700
From: leifwessman@hotmail.com (Leif Wessman)
Subject: =?ISO-8859-1?Q?removing_a_word_using_a_regexp_doesn't_w?= =?ISO-8859-1?Q?ork_with_the_characters_'=E5',_'=E4'_and_'=F6'?=
Message-Id: <64beeaad.0305200545.6e3d3c8f@posting.google.com>

$text = "det mandelträdet";
$text =~ s/\bdet\b//ig;

result  : "mandelträ"
expected: "mandelträdet"

Why isn't å,ä and ö working. Is there a workaround?

Leif


------------------------------

Date: Tue, 20 May 2003 13:15:24 GMT
From: "Blnukem" <blnukem@hotmail.com>
Subject: Array and html template
Message-Id: <MTpya.10025$OB5.4138086@news4.srv.hcvlny.cv.net>

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




------------------------------

Date: Tue, 20 May 2003 08:51:08 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Array and html template
Message-Id: <slrnbckcmc.1mo.tadmc@magna.augustmail.com>

Blnukem <blnukem@hotmail.com> wrote:

> I need some help I'm opening a text file and putting text information into
> @data
> Then I'm opening a remote 


What does "remote" mean when you say it?


> html template file 


There are many templating systems already developed, you should
consider using one of them instead of developing yet another one.


> 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


You appear to be confused as to the distinction between what is "code"
and what is "data". Understanding the difference is essential to
understanding programming in general.

The "@data" above is data, not code, so you'll need to process
the data as needed for your application.


> So my Perl question is how do I get @data into the template.


You are _already_ getting @data into the template!

I think you want to get the values contained in the @data array
into the template instead?

   s/\@data/ join '', @data /ge;  # untested


> # Sart building webpage
> open (NEWPAGE, ">/testpage/page.htm")|| &Error('open','file');
> flock(NEWPAGE, 2);


You should check the return value from flock() to verify that
you got what you asked for.


> print NEWPAGE "@template";


You are inserting spaces that were not in the original data. Is that
what you wanted to do?


> flock(NEWPAGE, 8);


You should never do that. It introduces a "race", which is exactly
what you are trying to protect against.

Just close() the filehandle, it will release the lock without a race.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 20 May 2003 04:28:05 -0700
From: g000ze@gmx.net (gooze)
Subject: awstats ignores HostAliases if using %virtualname
Message-Id: <e09c7315.0305200328.1927c5df@posting.google.com>

Hi there...

We are hosting a number of Webservers on different hosts running with
Lotus Domino Web Servers. We would like to collect webstatistics with
awstats. Unfortunately Lotus Domino Servers logs differently than
other webservers do, especially if there are virtual hosts on it.

Usually a webserver logs this way (common extended format): 
remotehost rfc931 authuser [date] "request" status bytes 

Lotus Notes does it this way: 
remotehost virtualhost authuser [date] "request" status bytes 

I cannot tell the Domino Server how to log, there is just the "Common
Extended Format" log style available in the configuration. I tried to
work around this by telling awstats to handle the logfiles
differently. Here is what I told the configuration file of awstats:

LogFormat="%host %virtualname %logname %time1 %methodurl %code %
bytesd %refererquot %uaquot"

Actually this works perfectly. The only problem is, that awstats
ignores all HostAliases.

Now my question: Does somebody know awstats? Is somebody able to
modify awstats so that awstats cares about both fields, the SiteDomain
AND the HostAliases, although the "%virtualname" value is in the
LogFormat field?

I know, I am expecting very much, but I never give up hoping!

ANY help will be very apreciated
Kind regards, Stefan
Zuerich Switzerland


------------------------------

Date: Tue, 20 May 2003 10:44:43 +0100
From: John English <je@brighton.ac.uk>
Subject: Best way to compare binary files?
Message-Id: <bactcg$od2$1@saturn.bton.ac.uk>

Can anyone suggest a good way to compare two binary files? I'm
currently doing something like this:

   while (read FIRST,$buf1,4096) {
     if (read SECOND,$buf2,length($buf1)) {
       if (length($buf1) > length($buf2)) {
         seek FIRST, length($buf2)-length($buf1), 1;
       }
       return "Mismatch" if ($buf1 ne $buf2);
     }
   }

It turns out that this is horribly inefficient -- for some reason,
FIRST reads 4K bytes every time but SECOND (a file on the same
hard disk) only gets 47 bytes (or 31 bytes) on each read. Dunno
why. Whatever, I end up comparing the file in miniscule chunks
and seeking all over the place in FIRST. As a reesult, rying to
compare multi-megabyte files is painfully slow.

Any better ideas?

-----------------------------------------------------------------
  John English              | mailto:je@brighton.ac.uk
  Senior Lecturer           | http://www.it.bton.ac.uk/staff/je
  Dept. of Computing        | ** NON-PROFIT CD FOR CS STUDENTS **
  University of Brighton    |    -- see http://burks.bton.ac.uk
-----------------------------------------------------------------



------------------------------

Date: 20 May 2003 11:24:09 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Best way to compare binary files?
Message-Id: <bad38p$pph$3@mamenchi.zrz.TU-Berlin.DE>

John English  <je@brighton.ac.uk> wrote in comp.lang.perl.misc:
> Can anyone suggest a good way to compare two binary files? I'm
> currently doing something like this:
> 
>    while (read FIRST,$buf1,4096) {
>      if (read SECOND,$buf2,length($buf1)) {
>        if (length($buf1) > length($buf2)) {
>          seek FIRST, length($buf2)-length($buf1), 1;
>        }
>        return "Mismatch" if ($buf1 ne $buf2);
>      }
>    }
> 
> It turns out that this is horribly inefficient -- for some reason,
> FIRST reads 4K bytes every time but SECOND (a file on the same
> hard disk) only gets 47 bytes (or 31 bytes) on each read.  Dunno
> why.

It shouldn't.  "read()" (as opposed to "sysread()") should never
give you short reads except on eof.

>      Whatever, I end up comparing the file in miniscule chunks
> and seeking all over the place in FIRST. As a reesult, rying to
> compare multi-megabyte files is painfully slow.

It shouldn't be necessary to restrict read() to the length of the
first buffer.  If the files are equal, both should deliver the exact
same sequence of buffers.  If they are different, so will be the
sequence of buffers.  The only case to consider is that the first
file may be shorter than the second, so we will have to check if
the second file is at eof when the first is.  The following works
for me:

    print cmp_file( @ARGV) ? "equal\n" : "not equal\n";

    ################################################################

    use constant BUF_SIZE => 4096;

    sub cmp_file {
        my ( $f1, $f2) = @_;
        open my $h1, $f1 or die "gah $f1: $!";
        open my $h2, $f2 or die "gah $f2: $!";
        binmode $h1; binmode $h2;
        my ( $buf1, $buf2);
        my $equal = 0;
        while ( read $h1, $buf1, BUF_SIZE ) {
            read $h2, $buf2, BUF_SIZE;
            last unless $equal = ( $buf1 eq $buf2);
        }
        return $equal and eof $h2;
    }

Anno



------------------------------

Date: Tue, 20 May 2003 11:33:09 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Best way to compare binary files?
Message-Id: <1560871ae8d04bf34605708a1077f1d4@TeraNews>

>>>>> "Anno" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:

Anno>     sub cmp_file {

And if you don't want to type all this in every time, use File::Compare
in the CPAN.

print "Just another Perl hacker,"

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: 20 May 2003 11:56:24 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Best way to compare binary files?
Message-Id: <bad558$pph$4@mamenchi.zrz.TU-Berlin.DE>

Randal L. Schwartz <merlyn@stonehenge.com> wrote in comp.lang.perl.misc:
> >>>>> "Anno" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
> 
> Anno>     sub cmp_file {
> 
> And if you don't want to type all this in every time, use File::Compare
> in the CPAN.

 ...or if you just want it to be correct.  My suggestion in the preceding
post is buggy.  Change the last line of "sub cmp_file" to

    return $equal && eof $h2;

Anno


------------------------------

Date: Tue, 20 May 2003 14:04:21 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: Best way to compare binary files?
Message-Id: <FBqya.48608$Ur1.38093@nwrddc03.gnilink.net>

John English wrote:
> Can anyone suggest a good way to compare two binary files?
[...]

I seem to remember that we had this very same question just last week or so.
Wasn't File::Compare the answer?

jue




------------------------------

Date: Tue, 20 May 2003 14:11:32 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Best way to compare binary files?
Message-Id: <3eca3738.3453605141@news.cis.dfn.de>

On Tue, 20 May 2003 14:04:21 GMT, "Jürgen Exner"
<jurgenex@hotmail.com> wrote:

>John English wrote:
>> Can anyone suggest a good way to compare two binary files?
>[...]
>
>I seem to remember that we had this very same question just 
>last week or so. Wasn't File::Compare the answer?

Isn't it always?

Following a Usenet newsgroup does tend to
induce deja vu.

In the Matrix it means "They changed something".

Here nothing changes.
-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


------------------------------

Date: Tue, 20 May 2003 10:50:27 -0400
From: "Ben Kennedy" <bkennedy@hmsonline.com>
Subject: Re: Best way to compare binary files?
Message-Id: <SvCcne2G9tpt3VejXTWcpQ@giganews.com>


"John English" <je@brighton.ac.uk> wrote in message
news:bactcg$od2$1@saturn.bton.ac.uk...
> Can anyone suggest a good way to compare two binary files? I'm
> currently doing something like this:

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.

--Ben Kennedy




------------------------------

Date: Tue, 20 May 2003 12:14:21 GMT
From: Andrej Hocevar <ah@siol.net>
Subject: Re: can fork() be an alternative to while (1)?
Message-Id: <slrnbck75u.4gs.ah@sonet.utopija.linux>

In article <20030520093616.084f7b57.john.thetenant-s@moving-picture.com>, John Strauss wrote:
> I wouldn't use fork(), but then I don't use curses.

It had, however, turned out to be a curses-related issue: I've
mistakenly put "nodelay(1)" at the top, which made it execute that
loop in question without waiting for a key first. It's working ok
now.

> Term::ReadKey from CPAN sounds like the ticket, but you may get 
> a better idea from one of these:
> 
> perldoc -q keyboard

Thanks for this one. It may help in future.

> perldoc -f select

This I don't quite understand yet ...

> If you don't care about being particularly efficient, you could 
> simply stick a "sleep (1)" in your "while (1)" loop to ease the 
> cpu burden.  or you can effect a finer grained sleep with select,
> see the above perldocs.

But my question was about efficiency, given the initial requests.
sleep() doesn't make much sense, you'll probably agree.

Thanks for the help,

    andrej

-- 
echo ${girl_name} > /etc/dumpdates


------------------------------

Date: Tue, 20 May 2003 14:24:14 GMT
From: Tweetie Pooh <tp601553@cia.gov>
Subject: Children killing parent SIGCHLD
Message-Id: <Xns93819CB384F8BTweetiePooh@62.253.162.105>

Hi all.

I am looking myself (google etc) but maybe someone else has encountered this.

I am writing a simple TCP type server program.  Listens on a port, on 
connection forks a process, handles data, passing out to a second port.  
Nothing complex here at all.  The clients essentially telnet on an write 
data.

Using the code in Perl Cookbook and Adv Perl as examples.

Essentially it works.  Connect, data in, process, out, target system OK.

Problem:  When client dies, disconnects the forked process dies.  That's OK, 
but so does the parent.

I use SIG(CHLD) to clean up defunct processes.  If I remove handles I get the 
zombies but the parent loops back to pick up another client.  With the 
handler the parent hits the cleanup routine then exits its loop and closes 
down.

Is there something else I need to do so the parent just returns to its main 
loop on a child death after cleanup?

TIA


------------------------------

Date: Tue, 20 May 2003 09:58:03 -0400
From: slack3r <slack3r@nowhere.com>
Subject: Combining lines of a text file
Message-Id: <8pckcv88lcq1ololnb0t700i986i0qri7o@4ax.com>

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!


------------------------------

Date: Tue, 20 May 2003 14:09:41 GMT
From: helgi@decode.is (Helgi Briem)
Subject: Re: Combining lines of a text file
Message-Id: <3eca3601.3453294284@news.cis.dfn.de>

On Tue, 20 May 2003 09:58:03 -0400, slack3r
<slack3r@nowhere.com> 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).

This Question is Frequently Asked.  Answers to Frequently
Asked Questions are found in the Perl documentation that
comes bundled with any installation of Perl.  

Said documentation can be searched and browsed using a
program called perldoc.

I will assume you have Perl installed on your computer.

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.


-- 
Regards, Helgi Briem
helgi DOT briem AT decode DOT is


------------------------------

Date: Tue, 20 May 2003 08:33:19 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Inserting a record into a table using a value from a sequence
Message-Id: <slrnbckbkv.1mo.tadmc@magna.augustmail.com>

Uma Mahesh <uma@bluemartini.com> wrote:

> I want to insert a record into a database table with a value from a sequence.


What is your Perl question?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 20 May 2003 14:58:37 GMT
From: ctcgag@hotmail.com
Subject: Re: Inserting a record into a table using a value from a sequence
Message-Id: <20030520105837.788$4f@newsreader.com>

uma@bluemartini.com (Uma Mahesh) wrote:
> Hi there,
>
> I want to insert a record into a database table with a value from a
> sequence.
>
> When ever I try to do that I get a invalid number.

What is invalid about the number?

> Any help or pointers are appreciated.

pointer 1) post some code that causes the error.
pointer 2) post the actual error message.
pointer 3) but not necessarily to a perl group, if the question is
           about databases and not perl.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service              New Rate! $9.95/Month 50GB


------------------------------

Date: 20 May 2003 05:34:05 -0700
From: lepore@brandeis.edu (bryan)
Subject: Re: making scalar variables from array elements, put into table
Message-Id: <dc6e7ce5.0305200434.4ba7a6d8@posting.google.com>

tiltonj@erols.com (Jay Tilton) wrote in message news:<3ec9abdd.63111378@news.erols.com>...
> : foreach $i (@equivalent_positions){
> :     if ( $i < 0  ) {
> : 	$i_alternate = (1+$i);
> : 	}
> :     else {
> : 	$i_alternate = (-1+$i);
> :     }
> : ##--- end excerpt ---##
> 
> One closing curly brace too early.  The rest of the loop would be of
> interest.  

what the... that was a typo.  the curly brace was later, an artifact
of my debugging. the numbers really do come out right - the loop
works.

>Most interesting would be the section of code where the table is
actually >printed.

gladly, but i had to use forward-slashes to indicate the line breaks.

format TABLE1 =                     
|(x y z): @##.####,     y, @##.#### | -(x y z): @##.####,     -(y),
@##.#### |
$SITE_B_X_COORD_1, $SITE_B_Z_COORD_1, $SITE_B_X_COORD_1_alternate, \
$SITE_B_Z_COORD_1_alternate;

etc...

> When the code creates the table, is it using the value in $i, the
> value in $i_alternate, or the values in $SITE_B_X_COORD_1 etc?  Or
> something else entirely?

it is using 0.0000 the way i have it because - vide infra...
 
> Where does that correctly calculated value end up, 

values - plural.  this is the thing of it.  my best answer is that it
gets overwritten (?) every pass through the loop, and - aha, i just
tried it - $i_alternate shows up in the table if i tell it to.  so
there's only one $i_alternate, e.g. 0.7310, and there are no
$SITE_B_X_COORD_1_alternate scalars.

> and how is that different from where you are looking for
> it?  

i'll leave that one for now...

there are warnings of "uninitialized value in formline" at the table
lines.  so the scalars i want are not being created with that loop,
and the table gets filled with 0.0000

i tried putting ` and ' and " around the i in $i_alternate in hopes
that perl would know it's supposed to be $SITE_B_X_COORD_1 but it
aborts.

-bryan


------------------------------

Date: 20 May 2003 12:13:29 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Memory problem
Message-Id: <bad659$pph$5@mamenchi.zrz.TU-Berlin.DE>

Nicholas Dronen  <ndronen@io.frii.com> wrote in comp.lang.perl.misc:
> Allanon <allanon@hotmail.com> wrote:

[code snipped]
 
> A> Now, as you can see, I slurp each log file into an array @lines, and then
> A> use a foreach loop to loop through the lines. I chose this method, over a
> A> while loop since at one point I need to check the subsequent line to the
> A> current line to make sure the requested file was successfully mailed.
> 
> Why not use:
> 
> 	while (<LOGFILE>) {
> 		# do stuff
> 		my $next_line = <LOGFILE> if $need_to_read_next_line;
> 	}

That is usually not a solution.  If the line you read ahead isn't the
one you expect (with a log file you can never be sure), it won't be
available to normal processing.  Some more trickery (like redo) will be
needed to fix this.

Anno


------------------------------

Date: Tue, 20 May 2003 14:27:02 GMT
From: Noerd <n_joeller@sharblbaziilyar.com>
Subject: newbie needs help please
Message-Id: <3ECA3B27.C9F598E9@sharblbaziilyar.com>

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)"



------------------------------

Date: Tue, 20 May 2003 15:54:02 +0100
From: John Strauss <john.thetenant-s@moving-picture.com>
Subject: Re: newbie needs help please
Message-Id: <20030520155402.0475f502.john.thetenant-s@moving-picture.com>

On Tue, 20 May 2003 14:27:02 GMT
Noerd <n_joeller@sharblbaziilyar.com> 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)"
> 

s/\(P\)/(papercover)/ or $_.=" (hardbound)"


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
drop the .thetenant to get me via mail


------------------------------

Date: Tue, 20 May 2003 09:59:47 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: newbie needs help please
Message-Id: <slrnbckgn3.2fm.tadmc@magna.augustmail.com>

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


------------------------------

Date: Tue, 20 May 2003 09:01:41 -0500
From: Ryan Yrreg <R-Yrreg@wiu.edu>
Subject: Re: PHP or Perl ?
Message-Id: <badcg5$e7s$1@mail1.wiu.edu>

	I would say that it depends on your background.  If you have done a lot 
with a language like C or Java, learn PHP.  If you have done a lot of 
Unix shell scripting, learn Perl, it will feel more natural to you.  I 
learned Perl becuase it was in vogue when I got into web programming a 
couple of years ago.  I am glad that I have the Perl experience that I 
do because it comes in handy all of the time (not just for web 
development).  Perl regular expressions (a geeky Computer Science term 
for pattern matching and text processing) are handy to know because they 
are supported in both PHP and Python (there may even be ways to use them 
in C/C++).  Also, note that www.cpan.org is a repository of pre - built 
open source Perl modules that will often have what you are looking for 
(so you don't have to reinvent the wheel).
	
	If you are new to Perl, it is easy to get started from the 
documentation that comes with it.  Type ‘perldoc perl’ (at a command 
prompt) to get a list of this documentation, or go to www.perldoc.com. 
Also, the Perl bibles are the Perl books from Oreilly.
	
	PHP is the open source web scripting language that is currently 
fasionable.  Although I have limited experience with PHP, I feel that 
the shift from PHP to Perl is due partly to that fact that Perl newbies 
are/were not exposed to the Perl modules that are helpful for web 
development (like CGI.pm).  Whereas PHP newbies cannot escape the 
helpful web development functionality because it is so incorporated into 
the language.  Since you are a Perl newbie interested in web 
development, check out this page which compares most of the useful web 
development Perl modules:
http://perl.apache.org/docs/tutorials/tmpl/comparison/comparison.html
If you need help installing any of these modules, let us know.  It is 
farily easy to install Perl modules onto a your own account using the 
cpam module.  If you decide to go the Perl route, check out 
www.perlmonks.org to get help on solving common problems.

	Recently, I have been doing some systems administration and find Perl 
much easier to maintain than PHP.  This is because with Perl, you can 
simply install a CPAN module into your local archive without having to 
mess with the Perl binary (the Perl interpreter itself).  But my 
experience with PHP has been that adding additional functions (GD and 
Freetype to be exact) involves recompiling PHP.  On a similar note, I 
find PHP's function namespace cluttered and scattered.  I prefer Perl's 
modules to PHP's large number of global functions which I quickly loose 
track of.  Perhaps I am being to hard on PHP, as I am new to it.  If 
anyone has an easier method of installing additional functionality to 
PHP without recompiling let me know.  Also, to PHP gurus: is 
pear.php.net to PHP as cpan is to Perl?

	As for Coldfusion, java servlets, or Python, I don't have enough 
experience with any of them to give an informed opinion.  However, if 
you are looking into java servlets, check out JSP (Java Server Pages).

-Ryan


Dieter D'Hoker wrote:
> How would you advice someone who wants to start learning a programmign
> language for developping websites ?
> learning PHP or Perl ?
> 
> Or maybe somethign else like Coldfusion , or java servlets , Python ?
> 
> and why ?
> 
> 



------------------------------

Date: Tue, 20 May 2003 13:48:36 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-hagin@DODGE_THISlido-tech.net>
Subject: Re: removing a word using a regexp doesn't w ork with the characters 'å', 'ä' and 'ö'
Message-Id: <Xns9381A082E93F7elhber1lidotechnet@62.89.127.66>

Leif Wessman wrote:

> $text = "det mandelträdet";
> $text =~ s/\bdet\b//ig;
> 
> result  : "mandelträ"
> expected: "mandelträdet"
> 
> Why isn't ?,ä and ö working. Is there a workaround?


perldoc perllocale


-- 
Cheers,
Bernard
--
echo 42|perl -pe '$#="Just another Perl hacker,"'



------------------------------

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 5010
***************************************


home help back first fref pref prev next nref lref last post