[18755] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 923 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu May 17 11:07:33 2001

Date: Thu, 17 May 2001 08:05:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <990111911-v10-i923@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 17 May 2001     Volume: 10 Number: 923

Today's topics:
    Re: "listen" to a file <real@earthling.net>
    Re: An Example Of A Polite FAQ <godzilla@stomp.stomp.tokyo>
    Re: An Example Of A Polite FAQ <me@my_no_spam.org>
    Re: An Example Of A Polite FAQ <godzilla@stomp.stomp.tokyo>
    Re: An Example Of A Polite FAQ <me@my_no_spam.org>
    Re: check if file exists with different extensions <pne-news-20010517@newton.digitalspace.net>
    Re: check if file exists with different extensions (Tad McClellan)
    Re: check if file exists with different extensions <nospam@peng.nl>
    Re: check if file exists with different extensions <nospam@peng.nl>
    Re: check if file exists with different extensions <alexis.roda@si.urv.es>
    Re: Connecting to MS Access with an Apache Server??? <cpryce@pryce.net>
    Re: Connecting to MS Access with an Apache Server??? <bart.lateur@skynet.be>
    Re: Excluding certain output variables? (Tad McClellan)
        Filehandling, opening & Reopnening <mika.morell@se.abb.com>
    Re: FOUND IT dynamic name for hashtable ... (Tad McClellan)
    Re: Hashes and such ... help ! (Tad McClellan)
    Re: i want to tokenize a string <joe+usenet@sunstarsys.com>
    Re: i want to tokenize a string <peb@bms.umist.ac.uk>
    Re: i want to tokenize a string (Tad McClellan)
    Re: Parse::RecDescent returning array ref (Randal L. Schwartz)
    Re: Parse::RecDescent returning array ref (Sweth Chandramouli)
    Re: Perl bytecode execution <clintp@budman.roalok1.mi.home.com>
    Re: Posting Guidelines for comp.lang.perl.misc ($Revisi <godzilla@stomp.stomp.tokyo>
    Re: Sending wav-file through perl-script <godzilla@stomp.stomp.tokyo>
    Re: Sending wav-file through perl-script <bart.lateur@skynet.be>
    Re: Sending wav-file through perl-script <godzilla@stomp.stomp.tokyo>
        splitting strings <cseeberg@sgi1.chemie.uni-hamburg.de>
        telnet.pm - argument "" isn't numeric <tmvatcher@Xbigfoot.com>
    Re: telnet.pm - argument "" isn't numeric <real@earthling.net>
    Re: timeout after STDIN ? <pne-news-20010517@newton.digitalspace.net>
    Re: timeout after STDIN ? <clintp@budman.roalok1.mi.home.com>
    Re: transform html to xhtml <pne-news-20010517@newton.digitalspace.net>
        word doc to txt <huhusven@xs4all.nl>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 17 May 2001 16:58:11 +0200
From: "Real" <real@earthling.net>
Subject: Re: "listen" to a file
Message-Id: <9e0ou7$fji$1@news.surfnet.nl>

"Peter Sĝgaard" <peter.sogaard@tjgroup.com> wrote in message
news:9e04lp$t0p$1@news.inet.tele.dk...
> Is it possible to have perl "listen to" a certain file, and then trigger
> some event when this file is updated( i.e. overwritten ).
> I can probably use sleep x seconds and then check the file status once in
a
> while and decide whether the file has been updated since last time i
> checked...but is there a more correct way of doing this?...if so, how? :)

I don't think there's a better way (other than check-stat / sleep /
check-stat-again) since in the FAQ the "tail -f" description does the exact
same thing. Of course, it uses seek() instead of stat(), but the sleep()
part is also in it.

Bye,
Real





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

Date: Thu, 17 May 2001 06:45:59 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B03D617.978307F0@stomp.stomp.tokyo>

Bart Lateur wrote:
 
> Godzilla! wrote:
 
> >Welcome to comp.lang.perl.misc newsgroup!
> ...
 
> Not bad. Not bad at all.
 
> Except for this:
 
> >3.  Social faux pas to avoid
> >     3d. Getting along with others
 
> Eh? You are wrong if you're trying to get along with others?
 
> The text under this heading surely points the other way, so this is a
> case of where the combination of these headings says something other
> than they would do by themselves.

Yes, I agree. My first thought was to eliminate this
topic of getting along with others entirely. It is
always difficult to advise an adult about behaving
appropriately; you cannot avoid sounding condescending.

However, I claim to be firm but fair. I tried to
retain as much of the original topics and wording
as possible in deference to others here and, to
respect the work of long standing regulars here.

My opinion is this section 3d is really not needed.
Troublemakers are already here and everywhere as you
know. New troublemakers are certainly not going to
bother with reading a newsgroup FAQ. Usually only
highly responsible people take time to read a
newsgroup FAQ.

The intent of my posting this is to demonstrate how
a FAQ can come across in a warm and friendly manner
yet impart important information in a matter-of-fact
peer fashion. It is not my intent to suggest my FAQ
should be adopted. It is an example and clearly, 
needs editing for grammar and spelling errors.

Godzilla!


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

Date: Thu, 17 May 2001 10:00:04 -0400
From: Dave VP <me@my_no_spam.org>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B03D964.EC1961AA@my_no_spam.org>

"Godzilla!" wrote:
> 
> Bart Lateur wrote:
> 
> > Godzilla! wrote:
> 
> > >Welcome to comp.lang.perl.misc newsgroup!
> > ...
> 
> > Not bad. Not bad at all.
> 
> > Except for this:
> 
> > >3.  Social faux pas to avoid
> > >     3d. Getting along with others
> 
> > Eh? You are wrong if you're trying to get along with others?
> 
<snip>
> My opinion is this section 3d is really not needed.
> Troublemakers are already here and everywhere as you
> know. New troublemakers are certainly not going to
> bother with reading a newsgroup FAQ. Usually only
> highly responsible people take time to read a
> newsgroup FAQ.
<snip>

This section would seem more appropriate as "2g", a guideline for
*posting* to clpm.  

I would encourage a reworking of the sentence beginning "You are an
adult....", as it is apparent that minors also participate in the group.


Dave


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

Date: Thu, 17 May 2001 07:25:20 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B03DF50.D905690C@stomp.stomp.tokyo>

Dave VP wrote:
 
> "Godzilla!" wrote:
> > Bart Lateur wrote:
> > > Godzilla! wrote:

> > > >Welcome to comp.lang.perl.misc newsgroup!

(snipped)

> I would encourage a reworking of the sentence beginning "You are an
> adult....", as it is apparent that minors also participate in the group.

"You are a mature responsible person...."

There are many ways to impart a message without running
into these problems of sounding condescending or causing
a segregation based on age, background knowledge and
the such.

Diplomacy is of utmost importance and, proves the
hardest talent of all to master.

Godzilla!


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

Date: Thu, 17 May 2001 10:40:33 -0400
From: Dave VP <me@my_no_spam.org>
Subject: Re: An Example Of A Polite FAQ
Message-Id: <3B03E2E1.466949FA@my_no_spam.org>

"Godzilla!" wrote:
> 
> Welcome to comp.lang.perl.misc newsgroup!
> 

<snipping a polite introduction> 

> 1. Before posting to comp.lang.perl.misc
> ________________________________________
> 
>  1a. Check the Perl Frequently Asked Questions (FAQ)
> 

<snipping helpful text> 

>     ( several links to mirror sites for Perl FAQ )
>
> 
>  1b. Check the other standard Perl docs (*.pod)
> 

<snipping more helpful text>

>     (possible examples of using the Perl search feature)
>

<snipping rest of msg>

Yes!  Having some concrete examples in these sections would be very
helpful to the uninitiated.  Maybe the first suggestion should be

	perldoc perlfaq

I find it amazing how many folks don't know that they can do something
as simple as this.  Well, I guess there's always going to be those who
don't read the READMEs/Release Notes/INTROs.

We must try to remember that one must *learn* to be an effective reader
(user) of FAQs, docs, etc.  Until one learns how to properly phrase the
question to be asked, FAQ checking generally returns less than
satisfactory results.  Giving new posters a few concrete examples may
get them on the right track.

Kira, this draft is an excellent reworking and it's great to see you
taking a lead in such a positive direction.

Dave


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

Date: Thu, 17 May 2001 16:40:43 +0200
From: Philip Newton <pne-news-20010517@newton.digitalspace.net>
Subject: Re: check if file exists with different extensions
Message-Id: <ilo7gtc35juhbdcufg0j2kf1he1ds9prm9@4ax.com>

On Thu, 17 May 2001 12:24:00 GMT, "Lex" <nospam@peng.nl> wrote:

> It only works fine if the image has the extension .gif .
> I would like it to work no matter if it is a .jpg .jpeg .gif .png (or all
> those in capitals)
> 
> I don't know how to accomplish this.

Use a loop. Put the possible extensions in an array. Then loop through
the array, each time sticking it on the end of the filename and testing
for existance. If you find a match, leave the loop (e.g. with last).

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 17 May 2001 09:48:02 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: check if file exists with different extensions
Message-Id: <slrn9g7lki.pvh.tadmc@tadmc26.august.net>

Lex <nospam@peng.nl> wrote:

>I have a perlscript that checks if a certain file exists, if so, it is shown
>on a web page.
>The code I'm using is:
>
> my $sourcefile = $rec{'ID'} ."a.gif";


Most folks would write that this way for better readability:

   my $sourcefile = "$rec{ID}a.gif";


> my $thumbfile  =
>'/usr/home/lex/htdocs/btsbos.nl/portfolio/fotos/'.$sourcefile;
>
>if (-e $thumbfile) {
>print qq|

[snip]

>Now this works fine, but i'd like to change something.
>
>It only works fine if the image has the extension .gif .
>I would like it to work no matter if it is a .jpg .jpeg .gif .png (or all
>those in capitals)


What should be done if there is more than one file with 
a common "basename"?

Loop and output them all? Use the first one found? ...


>I don't know how to accomplish this.


use opendir() to have a look around for files like that.

use grep() to filter the list of filenames.


>Can somebody help?


   # untested!
   my $fotodir = '/usr/home/lex/htdocs/btsbos.nl/portfolio/fotos';
   opendir(FOTOS, $fotodir) or die "could not open '$fotodir' directory $!";
   foreach my $file ( grep /^$rec{ID}a\.(jpe?g|gif|png)$/i, readdir FOTOS ) {
      print "$fotodir/$file\n";
   }
   closedir(FOTOS);


If the values in %rec might have regex metacharacters that you
want to be taken literally, then change to:

   foreach my $file ( grep /^\Q$rec{ID}\Ea\.(jpe?g|gif|png)$/i, ...
                             ^^        ^^
                             ^^        ^^ perldoc -f quotemeta


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


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

Date: Thu, 17 May 2001 14:45:20 GMT
From: "Lex" <nospam@peng.nl>
Subject: Re: check if file exists with different extensions
Message-Id: <4uRM6.144267$Uo2.3811641@zwoll1.home.nl>


"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrn9g7lki.pvh.tadmc@tadmc26.august.net...

<snip>

>
> What should be done if there is more than one file with
> a common "basename"?
>
In this case there can be only one


>
>    # untested!
>    my $fotodir = '/usr/home/lex/htdocs/btsbos.nl/portfolio/fotos';
>    opendir(FOTOS, $fotodir) or die "could not open '$fotodir' directory
$!";
>    foreach my $file ( grep /^$rec{ID}a\.(jpe?g|gif|png)$/i, readdir
FOTOS ) {
>       print "$fotodir/$file\n";
>    }
>    closedir(FOTOS);
>
>
> If the values in %rec might have regex metacharacters that you
> want to be taken literally, then change to:
>
>    foreach my $file ( grep /^\Q$rec{ID}\Ea\.(jpe?g|gif|png)$/i, ...
>                              ^^        ^^
>                              ^^        ^^ perldoc -f quotemeta
>

Thanks,

I'll go ahead and try!

Lex




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

Date: Thu, 17 May 2001 14:46:36 GMT
From: "Lex" <nospam@peng.nl>
Subject: Re: check if file exists with different extensions
Message-Id: <gvRM6.144277$Uo2.3811985@zwoll1.home.nl>


"Philip Newton" <pne-news-20010517@newton.digitalspace.net> wrote in message
news:ilo7gtc35juhbdcufg0j2kf1he1ds9prm9@4ax.com...

<snip>
>
> Use a loop. Put the possible extensions in an array. Then loop through
> the array, each time sticking it on the end of the filename and testing
> for existance. If you find a match, leave the loop (e.g. with last).
>
> Cheers,
> Philip

Thanks Philip,

that's what I guessed I had to do.

I have now 2 options (at least) and I'll go and work on it, and will let you
know if I could do with a bit more help

Lex




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

Date: Thu, 17 May 2001 16:55:47 +0200
From: Alexis Roda <alexis.roda@si.urv.es>
Subject: Re: check if file exists with different extensions
Message-Id: <3B03E673.E8DE13@si.urv.es>

Lex wrote:
> 
> Hi,
> 
> question:
> 
> I have a perlscript that checks if a certain file exists, if so, it is shown
> on a web page.
> The code I'm using is:
> 
>  my $sourcefile = $rec{'ID'} ."a.gif";
>  my $thumbfile  =
> '/usr/home/lex/htdocs/btsbos.nl/portfolio/fotos/'.$sourcefile;
> 
> if (-e $thumbfile) {
> print qq|
> <td><img src="http://www.peng.nl/btsbos.nl/portfolio/fotos/$rec{'ID'}a.gif"
> alt="" border="0">
> </td>
> |;
> }
> 
> Now this works fine, but i'd like to change something.
> 
> It only works fine if the image has the extension .gif .
> I would like it to work no matter if it is a .jpg .jpeg .gif .png (or all
> those in capitals)
> 
> I don't know how to accomplish this.
> 
> Can somebody help?

@extensions = ('gif', 'GIF', 'jpg', ...);

foreach $ext (@extensions) {
  my $sourcefile = $rec{'ID'} ."a.$ext";
  my $thumbfile  =
    '/usr/home/lex/htdocs/btsbos.nl/portfolio/fotos/'.$sourcefile;

  if (-e $thumbfile) {
    print qq|
<td><img
src="http://www.peng.nl/btsbos.nl/portfolio/fotos/$rec{'ID'}a.$ext"
alt="" border="0">
</td>
|;
  }
}

The problem with this script is that -e is case sensitive, so you should
add upper-case extensions to @extensions. If you allow only upper and
lower case extensions this may be acceptable, but if you allow mixedcase
extensions it will be preferable to use opendir and some kind of
filtering.



HTH
-- 
                                  ////
                                 (@ @)
---------------------------oOO----(_)----OOo------------------------
        Los pecados de los tres mundos desapareceran conmigo.
Alexis Roda - Universitat Rovira i Virgili - Reus, Tarragona (Spain)
--------------------------------------------------------------------


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

Date: Thu, 17 May 2001 08:53:01 -0500
From: Chris <cpryce@pryce.net>
Subject: Re: Connecting to MS Access with an Apache Server???
Message-Id: <B72941ED.5516%cpryce@pryce.net>

in article 2e16gtsu57d6686353llp1odhg35b5ddqj@4ax.com, Bart Lateur at
bart.lateur@skynet.be wrote on 05/16/2001 6:05 PM:

>> Our web site is running on an remote apache server and we have a MS access
>> database that we would like copy up to a directory and to be able to simply
>> exctract information from and show it in an HTML format.
> 
> It looks to me as if you're trying this on a Solaris machine. Jeezes,
> some people succeed to really amaze me.
> 
> AFAIK, MS Access is readable on a Win32 platform only, and even then,
> you need to have the proper parts of MS Access, the program, installed
> on your machine (they're called "Jet") or it still won't work.

You are not quite correct there. A Solaris Box can be made to access
database applications running on a Windows machine. This FAQ has some
excellent suggestions for the setup:

http://tlowery.hypermart.net/perl_dbi_dbd_faq.html

We use one of the products referenced in this FAQ, the EasySoft OOBridge.
Without the EasySoft Products. YMMV

[ earlier post referenced  ]
>>in article 9duv5t$ajf$1@news.xmission.com, Ryan at ryan@tuitions.com wrote on
>>05/16/2001 5:36 PM:

>> #!/usr/bin/perl
>> use DBI;
>> $dbh = DBI->connect("dbi:ODBC:'driver=Microsoft Access Driver (*.mdb);
>> dbq=major.mdb'",'','');
>> #do stuff...
>> $dbh->disconnect;

>> Im having trouble connecting to our database I keep getting this error:

>> Can't locate loadable object for module DBD::ODBC in @INC (@INC contains:

The error message indicates that the DBD::ODBC driver is not installed. It
can obtained from CPAN
(http://search.cpan.org/search?mode=module&query=DBD%3A%3AODBC).

This can be a tricky install, so be sure and actually read the README and
installation section before you try it. And please see the above referenced
FAQ by Thomas Lowery before the install as well.


> 
> You have to get a database engine running that does work on your
> machine, and import the data into that database. With the proper DBD
> driver, you should be able to get a connection, and extract the data, as
> you intended.

You can write a routine to extract the data and move it to a machine local
to the Web server. You might even see a performance benefit, unless you
needed access to the data in the Access database in realtime. It is not
necessary to the successful completion of your (earlier post) stated goals.

> p.s. The fact that you're running Apache looks totally irrelevant to me.
> The fact that your machine is Solaris, which you didn't mention but
> which I can deduce from you @INC paths, does matter.

To be clear, Apache, or another Web server is relevant, as op stated that
they wanted to serve the data as an HTML page. You'd need a Web server for
that. However, Apache is not the cause of the error stated in the earlier
post. 

cp



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

Date: Thu, 17 May 2001 14:10:57 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Connecting to MS Access with an Apache Server???
Message-Id: <v0n7gt8ro4h5b0pua3t7771ultge8vb7q9@4ax.com>

Chris wrote:

>You are not quite correct there. A Solaris Box can be made to access
>database applications running on a Windows machine. 

The guy justed wanted to OPEN an Access file on a Solaris box. He
doesn't have Access running on a connected Windows machine.

-- 
	Bart.


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

Date: Thu, 17 May 2001 08:48:39 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Excluding certain output variables?
Message-Id: <slrn9g7i57.pr2.tadmc@tadmc26.august.net>

David Soming <davsoming@lineone.net> wrote:

>Hi new to perl,


Why are you addressing only those new to Perl?

I'm not new to Perl. Hope it was OK for me to read this...   :-)


>I have this script which displays SSI environment variables in browser:
>  #!/usr/local/bin/perl


You should ask for all the help that you can get:

   #!/usr/local/bin/perl -w
   use strict;


>   foreach $key (sort keys(%ENV)) {

   next if $key =~ /^(UNIQUE_USER_ID|REDIRECT_UNIQUE_ID|REDIRECT_USER_NAME)$/;

>      print "$key = $ENV{$key}<p>";
>   }

>How can I exclude specific variables in the output namely;
>UNIQUE_USER_ID=
>REDIRECT_UNIQUE_ID=
>REDIRECT_USER_NAME=



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


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

Date: Thu, 17 May 2001 16:36:12 +0200
From: Mika Morell <mika.morell@se.abb.com>
Subject: Filehandling, opening & Reopnening
Message-Id: <3B03E1DC.94427749@no-spam-what-so-ever.se.abb.com>

Hi.

This is kind of anewbie question, first time for perl. I need to reread
the same file 18 times, is there a way to not having to open and close
it 18 times.  With this layout of the script it only reads the file
once. And if I move the opening/closing of LOGFILE inside the for loop
it takes forever. The important part of the script looks like this:

open (LOGFILE,"$tmplog") || die "YOu killed kenny!!! YOu Bastard\n";
for ($i = 1 ; $i <=$total; $i++) {
    open (OUTFILE,">>$outpath/$hosts[$nuffra].log.txt");
    while (<LOGFILE>){
                  if (/\ $hosts[$nuffra]\ /) {
       print OUTFILE ("$_");
      }
                     }
close OUTFILE|| die " Someone is bakin brownies\n";
$nuffra++;
}

//Mika




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

Date: Thu, 17 May 2001 09:08:58 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: FOUND IT dynamic name for hashtable ...
Message-Id: <slrn9g7jba.pvh.tadmc@tadmc26.august.net>

Marc GRIETENS <Marc.Grietens@REMOVE-THIS.alcatel.be> wrote:
>Marc GRIETENS wrote:
>> <snip>
>>
>>   @_[0]{@_[1]}=@_[2];
>>   }
>
>
>This worked for me :)


You have a strange definition of "worked" then   :-)  :-)


>@_[0]->{@_[1]}=@_[1]; 
                   ^
                   ^   s/1/2/;

You _typed_ code instead of copy/paste didn't you? Naughty you.


>and in the main:
>Addline(\%table,$key,$value)
>
>any comments/remarks/suggestions are still welcome however.
                      ^^^^^^^^^^

Enable warnings and fix what it complains about.


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


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

Date: Thu, 17 May 2001 08:37:33 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Hashes and such ... help !
Message-Id: <slrn9g7hgd.pr2.tadmc@tadmc26.august.net>

grodan_kermit <mums_mums83@hotmail.com> wrote:

>Subject: Hashes and such ... help !


Your question isn't about hashes, it is about references and
multilevel data structures.

Perl ships with several documents that are helpful in getting
a handle on multilevel data structures. The first of these is

   perldoc perlreftut

a tutorial on references. The info given there may be sufficient
to understand what is going on in the code below.

If you want more, then see these ones too:

   perldoc perlref
   perldoc perllol
   perldoc perldsc


>I'm having trouble understanding the first line in this snippet :
>
>foreach $data (@{$result->[0]->{"data"}}) {

   $result->[0]

derefs the first-level array.

   $result->[0]->{"data"}

derefs the second-level hash.

   @{$result->[0]->{"data"}}

derefs the third-level array.


>$result is the result of an SQL query
>$result =  $db->fetch($sql);


I don't see how the fetch method builds the multilevel data
structure that you have shown. Something is strange there...


>Could some friendly soul interpret this for me ?


perl has a friendly soul :-)

The Data::Dumper module is very helpful in seeing what is going
on:

   use Data::Dumper;

   # load up $result

   print Dumper($result);


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


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

Date: 17 May 2001 09:17:40 -0400
From: Joe Schaefer <joe+usenet@sunstarsys.com>
Subject: Re: i want to tokenize a string
Message-Id: <m3n18cxggb.fsf@mumonkan.sunstarsys.com>

Paul Boardman <peb@bms.umist.ac.uk> writes:

> > nachoman wrote in comp.lang.perl.misc:
> > } if i have a string like
> > }
> > } "mooo     ninja randy    dandy"
> 
> <snip split results>
> 
> > }
> > } however i want to include the whitespaces up to the next word and
> > } get the output like this 
> > }
> > } "mooo   "
> > } "ninja "
> > } "randy   "
> > } "dandy"
> > }

[...]

> how about something like:-
> 
> $string = "mooo     ninja randy    dandy";
> @results = $string =~ m/(\w+\s+)/g;
                                ^
ITYM "*" here.

-- 
Joe Schaefer      "Never interrupt your enemy when he is making a mistake."
                                               -- Napoleon Bonaparte


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

Date: Thu, 17 May 2001 14:35:23 +0100
From: Paul Boardman <peb@bms.umist.ac.uk>
Subject: Re: i want to tokenize a string
Message-Id: <3B03D39B.38BACF1D@bms.umist.ac.uk>

Joe Schaefer wrote:
> 
> Paul Boardman <peb@bms.umist.ac.uk> writes:
> 
> > > nachoman wrote in comp.lang.perl.misc:
<copious snippage>

> > how about something like:-
> >
> > $string = "mooo     ninja randy    dandy";
> > @results = $string =~ m/(\w+\s+)/g;
>                                 ^
> ITYM "*" here.


Yep.  You're right.

Cheers

Paul


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

Date: Thu, 17 May 2001 07:11:02 -0400
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: i want to tokenize a string
Message-Id: <slrn9g7ce6.pr2.tadmc@tadmc26.august.net>

nachoman <nachoman@ehpt.com> wrote:
>if i have a string like
>
>"mooo     ninja randy    dandy"
      ^^^^^           ^^^^   5 spaces and 4 spaces


>however i want to include the whitespaces up to the next word and get the output like this
>
>"mooo   "
      ^^^  3 spaces
>"randy   "
       ^^^ 3 spaces


eh?

I'll assume that is a mistake.


>any suggestions on how to do this?

   my @chunks = /(\S+\s*)/g;   # string to split is in $_
                               #   the parenthesis are optional


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


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

Date: 17 May 2001 07:11:33 -0700
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Parse::RecDescent returning array ref
Message-Id: <m18zjw9iay.fsf@halfdome.holdit.com>

>>>>> "Sweth" == Sweth Chandramouli <sweth> writes:

Sweth>    QuotedText: 
Sweth>       DoubleQuote TextChar(s?) DoubleQuote
Sweth>       { $return = join ('', @item[2..scalar(@item)-2]) }

@item is always what you see.  I see three items there.
So you're joining $item[2], which is stringifying the arrayref returned
from the repetition item, and then passing that up.

You want to go one level down:

        { $return = join ('', @{$item[2]}) }

And your grammar should work better, but you might simplify it
significantly by thinking of the list as a *comma separated* list
instead of "many comma terminated items followed by one standalone
item".  That comes out trivially as:

CSVLine: QuotedText(s Comma) { $item[1] is an arrayref of QuotedText's }

Then just define QuotedText, Comma, and you're done!

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: Thu, 17 May 2001 15:01:05 GMT
From: sweth+perl@gwu.edu (Sweth Chandramouli)
Subject: Re: Parse::RecDescent returning array ref
Message-Id: <RIRM6.2465$G5.669411@news1.rdc1.md.home.com>

In article <m18zjw9iay.fsf@halfdome.holdit.com>,
Randal L. Schwartz <merlyn@stonehenge.com> wrote:
>>>>>> "Sweth" == Sweth Chandramouli <sweth> writes:
>
>Sweth>    QuotedText: 
>Sweth>       DoubleQuote TextChar(s?) DoubleQuote
>Sweth>       { $return = join ('', @item[2..scalar(@item)-2]) }
>
>@item is always what you see.  I see three items there.
>So you're joining $item[2], which is stringifying the arrayref returned
>from the repetition item, and then passing that up.
	Yes.  My eyes must have glazed over when I was reading 
the manpage, because I now see (after Damian emailed me off-group to
point it out) that it quite clearly states that repetitions pass up
arrayrefs.  (I think my problem was that in one part of the tutorial
for the module, it mentions that using %item can be easier than using
@item, because the number of elements in the array can vary; for some
reason, I think I translated that in my head to "each matched element
is pushed onto @item", which obviously isn't true.)

>And your grammar should work better, but you might simplify it
>significantly by thinking of the list as a *comma separated* list
>instead of "many comma terminated items followed by one standalone
>item".  That comes out trivially as:
>
>CSVLine: QuotedText(s Comma) { $item[1] is an arrayref of QuotedText's }
	I actually started out with
CSVLine: QuotedText(s /,/)
	, but started adding other pieces in while trying to track
down my problem.

	Thanks for the comments,

	Sweth.

-- 
Sweth Chandramouli ; <sweth+perl@gwu.edu>


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

Date: Thu, 17 May 2001 13:31:10 GMT
From: "Clinton A. Pierce" <clintp@budman.roalok1.mi.home.com>
Subject: Re: Perl bytecode execution
Message-Id: <yoQM6.39887$V5.7896228@news1.rdc1.mi.home.com>

[posted and mailed]

Mark Warnes <mark.warnes@ntlworld.com> wrote:
> I am trying to compile a CGI script into Perl bytecode to save time
> loading and parsing. My script is running on an ISP who does not
> provide mod_perl unfortunately so I want to use bytecode to try and
> speed up the loading part.

Good luck, but I haven't had a lot of luck doing this for anything
other than trivial programs.

> My question is can I compile on a linux box to then run the bytecode
> on a Windows machine. Also, how do you execute the bytecode (.plc
> file)? Do I need a small wrapper script which will 'require' the
> bytecode file?

Here's the example from the Perl Developer's Dictionary
that uses this technique to run bytecode.  It's a shell script that 
goes through all of the necessary steps to do what you're looking
for:

	# Create a short perl program to compile
	cat << EOF > /tmp/hello.pl
	#!/usr/bin/perl -w
	print "Hello, world";
	EOF

	# Now translate into bytecodes.  These are 
	#   platform-independant, and not quite source code.
	perl -MO=Bytecode,-o,/tmp/hello.plb /tmp/hello.pl

	# Create a third file which has a normal preamble,
	#    uses ByteLoader, and then has the bytecode
	#    appended to the end.
	echo "#!/usr/bin/perl" > /tmp/hello_compiled.pl
	echo "use ByteLoader;" >> /tmp/hello_compiled.pl
	cat /tmp/hello.plb     >> /tmp/hello_compiled.pl

	# Now run it!
	chmod 755 /tmp/hello_compiled.pl
	/tmp/hello_compiled.pl	#  prints "Hello, world"

Your mileage will vary greatly, but this does work on the same platform.
The bytecode can't be moved between Windows <-> Linux though.  BUT, it 
should be perfectly possible to write a small program to remotely compile
your programs into bytecode and re-assemble them.  Kinda like this script
here.

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Thu, 17 May 2001 06:52:24 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Posting Guidelines for comp.lang.perl.misc ($Revision: 1.1 $)
Message-Id: <3B03D798.DE83FBE7@stomp.stomp.tokyo>

Scott R. Godin wrote:
 
>  "Godzilla! wrote:
>  | David Coppit wrote:
>  | > Godzilla! wrote:

(lots of snippage)

>  | Think of me as the egg which sticks to your teflon pan.
 
> How did you get the teflon to stick to the pan? Inquiring minds want to
> know.

With Godzilla egg white, of course. Does this egg you on?

Godzilla!


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

Date: Thu, 17 May 2001 07:17:15 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sending wav-file through perl-script
Message-Id: <3B03DD6B.E74F7023@stomp.stomp.tokyo>

Chris wrote:

> Godzilla! wrote:
> > Chris wrote:

> > (snipped previous article)

(more snippage)

> > > you could try calling the script in this fashion

> > > http://mydomain.com/cgi-bin/waveprocess.pl?sound.wav

> > > the browser sees the last .wav and uses that as the file extension and
> > > therefore the helper program gets a proper extension

> > My compliments. I tried your method and it does work
> > on a Sun Solaris / Mozilla 4.x combination. This will
> > most likely work on many system / browser combinations.
 

> the same script will work with different files and types
 
> http://mydomain.com/cgi-bin/waveprocess.pl?sound1.wav
> http://mydomain.com/cgi-bin/waveprocess.pl?sound2.mid

Yes, you can also have one single script handle all sound
files quite well. I have to confess, I've been using this
method of yours, a mild modification, for years.

http://la.znet.com/~callgirl/rockmusi.html

If you examine my posted links for individual midi
files, they reference a single script which serves
as a hub for loading based on a query string.

However, it would not have been gracious of me to
steal your thunder. Nevertheless, you have added
many important points and methods, others can put
to use. I may even try some of your methods.


> > Say, you have any secret methods for printing both
> > html and a binary file with one script?
 
> ? I am not sure what you mean by this.
 
> are you saying the user clicks on a link and a web page
> is displayed, and once displayed the browser commences
> the download of a binary file?

In a sense yes. Mixing of content types without an error.
A prime example which pops into my mind, is being able
to mix html content type with plaintext content type.

True problem is browsers not being able to recognize
content type by extension and, assign a correct extension
based on content type. My opinion is browsers should be
able to assign an extension based on content type, such
as mid, ra, ru, wav and others.

In the future, I am sure this will change as internet related
technology advances. Most likely, assignment of extensions
based on single content type will be first, followed by
formats for multiple content types.

I believe the heart of the problem is browser software
developers are not savvy about scripts and how scripts
operate as common gateway interfaces. It seems their
expertise lies mostly in everyday html / java methods.
 
Godzilla!


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

Date: Thu, 17 May 2001 14:22:45 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Sending wav-file through perl-script
Message-Id: <ein7gt8tvr73t71p9rv85lm90recidp0qv@4ax.com>

Godzilla! wrote:

>There is an inherent problem, least with Mozilla. A browser
>downloads a sound file, wav, midi, au, whatever, then stores
>it in a browser cache. Unfortunately, .pl and .cgi files
>are not stored in a cache, not in a true sense, there is
>no related extension in most cases, which is really how
>it should be. A browser downloads an audio file via a script
>just fine but does not assign an audio extension because it
>originates through a script. A helper application is executed
>and is referenced to this sound file in cache, but there is no
>extension or, in rare cases, a wrong extension. It cannot be
>played; the sound application cannot recognize what type of
>audio file is present. 

The PATH_INO mechanism should work, except that IIS, "for security
reasons", doesn't support it by default:

	http://mydomain.com/cgi-bin/waveprocess.pl/sound.wav

This should call the script at
http://mydomain.com/cgi-bin/waveprocess.pl with $ENV{PATH_INFO} set to
"/sound.wav". The browser  doesn't know better than that "sound.wav" is
the name of the file.

-- 
	Bart.


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

Date: Thu, 17 May 2001 07:41:01 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Sending wav-file through perl-script
Message-Id: <3B03E2FD.4DC370C4@stomp.stomp.tokyo>

Bart Lateur wrote:
 
> Godzilla! wrote:
 
(snipped problem with browser not setting extension on content type)
 
> The PATH_INO mechanism should work, except that IIS, "for security
> reasons", doesn't support it by default:
 
>         http://mydomain.com/cgi-bin/waveprocess.pl/sound.wav
 
> This should call the script at
> http://mydomain.com/cgi-bin/waveprocess.pl with $ENV{PATH_INFO} set to
> "/sound.wav". The browser  doesn't know better than that "sound.wav" is
> the name of the file.
 
It is a real problem, huh? Here we are having to develop all
types of methods to "force" a browser to set an extension
based on content type. When people first encounter this,
if they are like me, you would expect content type to be
the deciding factor on an extension. Not so!

More exasperating, if you load a sound file, such as a midi
file, it plays and all, just great. However, if you right
click on this file to save it to disk, it will be saved
as "untitled.mid" in the case of a midi file and similar
for other sound files. How these files are handled, how
they are stored in cache, is quite screwy. So you have
a problem of no extension assignment based on content
type and, a problem of no original name assignment for
a cached file.

Similar problem with binary graphics exists but you can
download by original name by direct link. However in
cache, no true name assignment is made.

Godzilla!


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

Date: Thu, 17 May 2001 16:44:53 +0200
From: Christian Seeberger <cseeberg@sgi1.chemie.uni-hamburg.de>
Subject: splitting strings
Message-Id: <3B03E3E5.535224BD@sgi1.chemie.uni-hamburg.de>

Hi all !

I want to split a string, so that each letter of it is an element in an
array. My idea is something like:

$string = "abcdefg";
@array = split /magic reg exp/, $string;

@array shoud look like (a,b,c,d,e,f,g) after the split. What is the
'magic reg exp' I need in the code above ?? Is it possible to do it this
way at all ?? Up to now I use a construct with substr() and suchlike,
but I just have the feeling, thet there is a better, more elegant way of
oing this.

TIA

Chris


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

Date: Tue, 15 May 2001 17:41:24 -0700
From: "Toni Vatcher" <tmvatcher@Xbigfoot.com>
Subject: telnet.pm - argument "" isn't numeric
Message-Id: <9dsjk6$8ud$1@nnrp2.phx.gblx.net>

I'm getting the following warning from Net::Telnet

Argument "" isn't numeric in gt at C:/Perl/site/lib/Net/Telnet.pm line 2569.

In looking at telnet.pm, the procedure generating the warning is being
passed a single parameter ((stat $self)[11]) and then the code is assigning
the parameter to a scalar as follows :

my ($blksize) = @_;

The error occurs on the following line :

    return $blksize
         if defined $blksize and $blksize > 0 and $blksize <= 1_048_576;

So, $blksize is defined but it's the null string.

Am I doing anything wrong?  I temporarily modified telnet.pm to make sure
that $blksize isn't
the null string.... but, that's probably not the real solution.




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

Date: Thu, 17 May 2001 16:51:18 +0200
From: "Real" <real@earthling.net>
Subject: Re: telnet.pm - argument "" isn't numeric
Message-Id: <9e0oha$fbt$1@news.surfnet.nl>

"Toni Vatcher" <tmvatcher@Xbigfoot.com> wrote in message
news:9dsjk6$8ud$1@nnrp2.phx.gblx.net...
> I'm getting the following warning from Net::Telnet
>
> Argument "" isn't numeric in gt at C:/Perl/site/lib/Net/Telnet.pm line
2569.
>
> In looking at telnet.pm, the procedure generating the warning is being
> passed a single parameter ((stat $self)[11]) and then the code is
assigning
> the parameter to a scalar as follows :
>
> my ($blksize) = @_;
>
> The error occurs on the following line :
>
>     return $blksize
>          if defined $blksize and $blksize > 0 and $blksize <= 1_048_576;
>
> So, $blksize is defined but it's the null string.
>
> Am I doing anything wrong?  I temporarily modified telnet.pm to make sure
> that $blksize isn't the null string.... but, that's probably not the real
solution.

I've written a couple of scripts using the Telnet module, without any
problems.

You're not telling very much about your own script. It's in the
_optimal_blksize routine but I wouldn't know when it's being called. A small
part of your script might shed some light. Also, which version of Telnet are
you using ?  I'm using the latest version ( $VERSION = "3.02"; )

Bye,
Real





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

Date: Thu, 17 May 2001 16:20:06 +0200
From: Philip Newton <pne-news-20010517@newton.digitalspace.net>
Subject: Re: timeout after STDIN ?
Message-Id: <vfn7gt45nd70nk48a84q966p8b8e9ddfdi@4ax.com>

On Thu, 17 May 2001 13:23:59 +0200, "Sebastian Ramos" <ramos@terra7.de>
wrote:

> i want my perlscript to continue with next line if nothing happens after
> waiting 10 seconds for $input = <STDIN>;
> 
> is this possible without the use of any sockect or IO ???

No, I don't think it's possible to read from standard input without the
use of I/O.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 17 May 2001 14:51:32 GMT
From: "Clinton A. Pierce" <clintp@budman.roalok1.mi.home.com>
Subject: Re: timeout after STDIN ?
Message-Id: <UzRM6.40192$V5.7924248@news1.rdc1.mi.home.com>

[posted and mailed, apologies if duplicate appears new news software]

Sebastian Ramos <ramos@terra7.de> wrote:
> i want my perlscript to continue with next line if nothing happens after
> waiting 10 seconds for $input = <STDIN>;

From the Perl Developer's Dictionary, alarm() entry example.  This waits
three seconds for a response and picks a default if no answer is received.


	# Time out an input operation
	$timeout=3;  # How long to wait...
	eval {
		local $SIG{ALRM}=sub { die "timeout"; };
		print "Respond y/n in $timeout seconds: ";
		alarm $timeout;
		$a=<>;  # Wait for slow user...
		alarm 0;
	};
	if ($@) {
		die unless  ($@ =~ /timeout/);
		print "Using default of Yes\n";
		$a="Yes";
	}

-- 
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary -- May 2001
"If you rush a Miracle Man,     for details, see http://geeksalad.org     
	you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Thu, 17 May 2001 16:41:37 +0200
From: Philip Newton <pne-news-20010517@newton.digitalspace.net>
Subject: Re: transform html to xhtml
Message-Id: <rno7gtom6ghvraddnr0n6sr167lrqvh8g3@4ax.com>

On Thu, 17 May 2001 14:36:24 +0200, "Marco Tölle" <marco@uni.de> wrote:

> Can anyone tell me how to transform HTML to XHTML using Perl ?
> Is there a module ?

Not specifically. I suppose you could hack something together using
HTML::TokeParser (or another HTML parser of your choice), however.

Cheers,
Philip
-- 
Philip Newton <nospam.newton@gmx.li>
Yes, that really is my address; no need to remove anything to reply.
If you're not part of the solution, you're part of the precipitate.


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

Date: Thu, 17 May 2001 16:49:55 +0200
From: sven <huhusven@xs4all.nl>
Subject: word doc to txt
Message-Id: <3B03E513.50C16308@xs4all.nl>

Hi,

I want to extract all ascii strings in a microsoft word document. I am
not interested in layout or anything, just in the text.

I did something like:

while ($line = <FileHandle>) {
  $line =~ s/[^A-Za-z0-9]+/ /g;
  ...
}

but this tends to produce strings, that are not visible in the document
at all.

Any suggestions ?


thanks in advance, Sven









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

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


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