[18255] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 423 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 5 21:05:59 2001

Date: Mon, 5 Mar 2001 18:05:19 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <983844319-v10-i423@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 5 Mar 2001     Volume: 10 Number: 423

Today's topics:
        (Help Needed) <ctackett@pirchplace.com>
    Re: (Help Needed) <bwalton@rochester.rr.com>
    Re: checkbox problem <webmaster@webdragon.munge.net>
    Re: Dynamic naming of arrays or hashes <webmaster@webdragon.munge.net>
        Feeding value pairs to ASP scripts? horribly@bogus.com
    Re: Feeding value pairs to ASP scripts? (Steven Smolinski)
        HELP!!!! perl script that writes to a text database que <alan@afdsolutions.com>
    Re: HELP!!!! perl script that writes to a text database <bwalton@rochester.rr.com>
    Re: HELP!!!! perl script that writes to a text database <bwalton@rochester.rr.com>
    Re: How Do I UUEncode (Tony L. Svanstrom)
    Re: How to list installed modules (MD5) <webmaster@webdragon.munge.net>
        Installing IO::pty on Win32 <rob_lundXOXO@pacbell.net>
    Re: libnet and Net::SMTP config.pm is wrong <gerard@NOSPAMlanois.com>
    Re: Magic Marker <wayne@joynes.fsbusiness.co.uk>
    Re: Magic Marker <Anonymous_Account>" <remailer@anon.xg.nu>
        Opening files on other Windows machines <iain_hosking@hotmail.com>
    Re: Perl, Cookies, and Apache. <parrot0123@yahoo.ca>
    Re: perl-ize and optimize <krahnj@acm.org>
        Regex question (newbie) <usenet@consulting.net.nz>
    Re: Regex question (newbie) (Tad McClellan)
    Re: Regex question (newbie) <usenet@consulting.net.nz>
    Re: regexp and parenthesis ... <godzilla@stomp.stomp.tokyo>
    Re: regexp and parenthesis ... <ren@tivoli.com>
    Re: regexp and parenthesis ... <godzilla@stomp.stomp.tokyo>
        Small problem: dup'ing DATA and $. (Clinton A. Pierce)
    Re: Submitting Forms from Code <webmaster@webdragon.munge.net>
    Re: Uploading a file <webmaster@webdragon.munge.net>
        use strict (vars, etc.) <cadet@alum.mit.edu>
    Re: use strict (vars, etc.) <brondsema@my-deja.com>
    Re: use strict (vars, etc.) <bwalton@rochester.rr.com>
    Re: why won't "format FILEHANDLE" work?? <krahnj@acm.org>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 5 Mar 2001 18:52:08 -0500
From: "C. Tackett" <ctackett@pirchplace.com>
Subject: (Help Needed)
Message-Id: <OEVo6.155$l5.33207@news1.iquest.net>

My friend and I were wondering if you're familiar with any perl script out
there that will allow me to insert a webpage from another server to a
particular file in our server via ssi or perhaps through regular cgi file?
What we want to accomplish is to download a particular web page from another
server (either html or cgi) and have it inserted to our own web page (yes we
have the permission to insert the file. we're just unsure on how to proceed
with this =)






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

Date: Tue, 06 Mar 2001 01:28:49 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: (Help Needed)
Message-Id: <3AA43E44.5C1CD56F@rochester.rr.com>

"C. Tackett" wrote:
> 
> My friend and I were wondering if you're familiar with any perl script out
> there that will allow me to insert a webpage from another server to a
> particular file in our server via ssi or perhaps through regular cgi file?
> What we want to accomplish is to download a particular web page from another
> server (either html or cgi) and have it inserted to our own web page (yes we
> have the permission to insert the file. we're just unsure on how to proceed
> with this =)

I assume you mean you want to do this live, rather than just making a
copy of the page and pasting it into your HTML when you edit your page. 
If so, you can get the page with:

    use LWP::Simple;
    $content=get('http://www.server.com/path/to/file.html');

Then you can do with $content whatever you please.  If $content is
undef, the get failed.  See:

    perldoc LWP::Simple
--
Bob Walton


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

Date: 6 Mar 2001 00:33:05 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: checkbox problem
Message-Id: <981b81$tcd$0@216.155.32.13>

In article <7Oco6.1655$Sz1.580611@typhoon2.ba-dsg.net>, mnc@admin.u.nu 
(Miguel Cruz) wrote:

 | Alan Hood <gi59@dial.pipex.com> wrote:
 | > I seem to have a problem passing a check box value to a CGI script.
 | > If the box is NOT checked then the script returns an error.
 | > If it is all seems OK.
 | > Can anybody help?
 | 
 | There is probably a bug in your script.
 | 
 | Is that helpful?
 | 
 | You probably need to provide more information before anyone can help you
 | much further. What does the relevant code look like? What is the error?


Unfortunately, Alan's original has already expired off my apparently 
small and starved newsfeed. However, I'd only like to add the comment 
that in all liklihood there is no 

    use CGI qw/:standard/;

in his script. 

:) 

The most recent version and complete docs are at
    <http://stein.cshl.org/WWW/software/CGI/>

<include standard.advice>
    using -w or warnings?
    using strict? 
    no? 
    you should be.
</end>

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: 6 Mar 2001 01:28:18 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: Dynamic naming of arrays or hashes
Message-Id: <981efi$2pv$0@216.155.32.13>

In article <3aa2d120.2e6a$359@news.op.net>, mjd@plover.com (Mark Jason 
Dominus) wrote:

 | OTR Comm wrote: 
 | >I will use your approach so I can turn 'use strict' back on.
 | 
 | That is a little like saying you have decided to stop setting your
 | furniture on fire, because you want to be able to turn your smoke
 | alarms back on.

is this an excellent example for that "c.l.p.m regular's posting style 
guide" or what? :D 

*muttergrump* *mopping keyboard* *grumblesmurf*

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Tue, 06 Mar 2001 00:24:18 GMT
From: horribly@bogus.com
Subject: Feeding value pairs to ASP scripts?
Message-Id: <3aa42c80.260192517@news.berkeley.edu>

Hi,

When I setup a perl script cgi-bin form, I frequently like to test it
by adding ?value0=foo&value2=bar to the URL line in a web browser.
Now, I'm trying to login to an asp script on a server not in my
control using LWP and the value pair method and it fails. It also
fails directly from a web browser.  Is there a different "trick" for
feeding value pairs to asp scripts?   

thanks.


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

Date: Tue, 06 Mar 2001 00:39:41 GMT
From: sjs@linux.ca (Steven Smolinski)
Subject: Re: Feeding value pairs to ASP scripts?
Message-Id: <slrn9a8h2d.5ab.sjs@ragnar.stevens.gulch>

[Note more evidence for the spamtrapped email bogosity indicator.]

horribly@bogus.com <horribly@bogus.com> wrote:
>                                Is there a different "trick" for
> feeding value pairs to asp scripts?   

What did they say on the ASP newsgroup?

Steve
-- 
Steven Smolinski => http://www.steven.cx/


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

Date: Tue, 06 Mar 2001 00:13:39 GMT
From: "alan scanlon" <alan@afdsolutions.com>
Subject: HELP!!!! perl script that writes to a text database question.
Message-Id: <TYVo6.28684$W05.6105347@news1.rdc1.mi.home.com>

my perl script below writes to a text database that reads each entry by a
new line. the problem is that whenever a user enters data useing a
multiline-text box input form, where ever they push enter to go to the next
line in the textbox it also jumps down to the next line in my text database
file making only the first line of the entry available. what i need is for
whenever they push enter in the input text box to switch it to a <br> in the
database file and keep the entire entry on one line in my database file.

please let me know of the best solution to fix my existing code.

thank you in advance, alan (aka: perl_newbie)


------the part of my perl script that needs help starts here------

sub change_preferences {
     $data="preferences.txt";
     $tempfile="$data.tmp";

     open(FILE, $data) or die "Error opening file: $data $!\n";
     open (TEMP, ">$tempfile") or die "Error opening file: $!\n";

     flock TEMP, $EXCLUSIVE;
     $temp = "";
     while(<FILE>)
     {
          ($key,$value) = split /\|/, $_;

          $val = $q->param($key);
          if ($q->param($key))
          {

               $preferences{$key} = $q->param($key);

               chomp $preferences{$key};
               $temp .= "$key\|$val\n";
          }
          else
          {

         chomp $value;
               $preferences{$key} = $value;
               $temp .= $_;

          }
     }

     chomp $temp;
     print TEMP $temp;
     flock FILE, $EXCLUSIVE;
     unlink($data);
     rename($tempfile,$data);
     flock FILE, $UNLOCK;
     flock TEMP, $UNLOCK;
     close(TEMP);
     close(FILE);

}

sub set_preferences {
     $data="preferences.txt";
     open(FILE, $data) or die "Error opening file: $data $!\n";
     while(<FILE>)
     {
          ($key,$value) = split /\|/, $_;
          chomp $value;
          $preferences{$key} = $value;
  }


     close(FILE);
}








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

Date: Tue, 06 Mar 2001 01:16:11 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: HELP!!!! perl script that writes to a text database question.
Message-Id: <3AA43B51.79F206ED@rochester.rr.com>

alan scanlon wrote:
> 
> my perl script below writes to a text database that reads each entry by a
> new line. the problem is that whenever a user enters data useing a
> multiline-text box input form, where ever they push enter to go to the next
> line in the textbox it also jumps down to the next line in my text database
> file making only the first line of the entry available. what i need is for
> whenever they push enter in the input text box to switch it to a <br> in the
> database file and keep the entire entry on one line in my database file.
> 
> please let me know of the best solution to fix my existing code.
 ...
Well, you should probably just convert the various possible forms of
newlines in your data into <br>, which could be done with:

     $var=~s/[\012\015]+/<br>/g;

assuming that variable $var has your data in it.  That will convert any
run of carriage return and newline characters into a <br>, and will take
care of the problem whether the data comes at you in Unix, Windoze, or
Mac ASCII format, and will also convert several returns in a row to a
<br> (those nasty users!).
-- 
Bob Walton


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

Date: Tue, 06 Mar 2001 01:23:56 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: HELP!!!! perl script that writes to a text database question.
Message-Id: <3AA43D24.A4B0AE1F@rochester.rr.com>

Bob Walton wrote:
 ...
> Well, you should probably just convert the various possible forms of
> newlines in your data into <br>, which could be done with:
> 
>      $var=~s/[\012\015]+/<br>/g;
> 
> assuming that variable $var has your data in it.  That will convert any
> run of carriage return and newline characters into a <br>, and will take
> care of the problem whether the data comes at you in Unix, Windoze, or
> Mac ASCII format, and will also convert several returns in a row to a
> <br> (those nasty users!).
> --
> Bob Walton

Just thought maybe I should followup with a warning that, since you are
treating your user's input as HTML code, you might want to strip out any
nasties the user might insert, like, for example:

    <a href="file://path/to/some/secret/file">click here for goodies</a>

When you display this back to the user, they will get a link that will
display your secret/file on your server computer.  There might even be
more nefarious things a user could insert into such a security hole.
-- 
Bob Walton


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

Date: Tue, 06 Mar 2001 01:36:25 GMT
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: How Do I UUEncode
Message-Id: <1epttnw.11xz0lw1wbebcwN%tony@svanstrom.com>

Bjoern Kaiser <cheesy@upb.de> wrote:

> how do I uuencode a binary file to send it as an Email-Attachment with
> sendmail.

Read the fine manual (binmode and pack), then use a module for the
mailing; or you could learn a lil bit about e-mailformats in RFC-land
<URL:http://www.rfc-editor.org/> and read up on open in perl (alt. some
of the piping stuff) as well as checking how the local mail stuff likes
to get the data.


        /Tony


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

Date: 5 Mar 2001 23:26:02 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: How to list installed modules (MD5)
Message-Id: <9817aa$o58$0@216.155.32.13>

In article <R7Mo6.3317$LD5.22092@news1.oke.nextra.no>, "Børge Haga" 
<borge.haga@nextra.spamno.com.invalid> wrote:

 | 1) This is probably a stupid question, but is there an easy way to detect
 | which modeules have been installed for a Perl installation? I need to
 | have MD5 installed, but I'm not sure if it's part of the standard
 | distribution and I don't even know which distribution have been
 | installed on the machine in question.

Digest::MD5 is, I believe, what you want. 

perl -MCPAN -e shell
cpan> i Digest::MD5
cpan> install Digest::MD5

 | 2) If it's not installed, where is the correct place to go and get it?

see above :) or www.cpan.org

Here's a little something I put together a while back.. feel free to use 
it; I've made periodic changes to it and will eventually offer it on my 
website or upload it somewhere for public consumption. 

#!/usr/bin/perl -w
# visualized and created by Scott R. Godin, 12/30/2000 
# last update March 5, 2001
# webmaster@webdragon.net, http://www.webdragon.net/
######
use strict;

# current macperl port 
#http://www.perl.com/CPAN/authors/id/CNANDOR/Storable-0.6@4-bin-1-Mac.tgz
use Storable 0.604; 

use File::Spec 0.82; 

# current version 1.59. 
# perl -MCPAN -e shell
# cpan> install CPAN 
# ... do NOT install Bundle::CPAN!!! (breaks things on 5.004 MacPerl)
use CPAN 1.59; 

# set to 0 if you don't want the output redirected to a file 
# under MacOS. 
use constant MACOS_SAVEFILE => 1; 

my $savefile = 
   File::Spec->catfile( File::Spec->curdir(), 'ModuleCheck.txt' );
my $storefile = 
   File::Spec->catfile( File::Spec->curdir(), 'installed_modules.stor' );

sub checkmodule () {
    my %installed_modules = ();
    print "Checking Modules...Please stand by.. ",
          "the cursor will spin for a minute or so.\n";
    print "GO get some coffee! You Deserve it! :-D\n";
    for my $mod (CPAN::Shell->expand("Module","/./")){
        next unless $mod->inst_file;
        # MakeMaker convention for undefined $VERSION:
        $installed_modules{ $mod->id } = [ 
          (($mod->inst_version eq "undef") ? '' : $mod->inst_version), 
          (($mod->cpan_version eq "undef") ? '' : $mod->cpan_version), ];
    }
    store \%installed_modules, $storefile; # uses Storable.pm
    print "Done and stored.\n\n";
}

sub readstored () {
    my $ref = retrieve($storefile) or die "$!"; # Storable again
    my $last = '';

    # did this because not enough buffer space to display entire list 
    # in MacPerl. bleh. include for MacOS as there's no way to redirect 
    # buffer output to a file, otherwise send to buffer and let user  
    # direct it to a file if they so choose, via typical unix 
    # convention: ./moduletest.plx > outputfile.txt
    if ( $^O eq 'MacOS' && MACOS_SAVEFILE) {
        print "Now retrieving Module data; output sent to $savefile\n";
        open STDOUT, ">$savefile" or die "$!";
    }
    print 
     "Listing all Installed Modules and Versions where available...\n\n";

    foreach  (sort {uc($a) cmp uc($b)} keys %{$ref}) {
         /^(\w+)\:{0,2}.*$/;
        my $this = $1;
        print  "-" x 87, "\n" if ($last ne $this);
        printf "Installed Module: %-35s", $_, ","; 
        printf " Version: %-9s", $ref->{$_}[0], ",";
        printf " CPAN: %-10s", $ref->{$_}[1];
        print  "\n";
        $last = $this;
    }
}

# if the storefile already exists, use it to save time. 
# delete it to re-run the check. 
if (-e $storefile) {
    print "Using existing .stor file for brevity.\n",
          "Delete '$storefile' and re-run the script if you wish to 
update.\n\n";
    readstored;
} else {
    checkmodule;
    readstored;
}

exit 0;

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Mon, 5 Mar 2001 16:28:28 -0800
From: "jibbering poster" <rob_lundXOXO@pacbell.net>
Subject: Installing IO::pty on Win32
Message-Id: <O7Wo6.193$p_3.104533@news.pacbell.net>

I'm trying to install and use Expect.pm, but it requires IO:Pty, which is a
bugger to install.   I tried to 'perl makefile.pl' for IO::Pty, but I needed
a C compiler.   I installed DJGPP, but make complains when I try to run it.

Gee... It sure is tough to use the Expect module in a Windwos environment.
If anyone has Successfully run the expect module in Windows, can you PLEASE
email me the method you used to install it at:

Rob_LundWXYZ@hotmail.com removing the WXYZ...

thanks sooo much for any help on this!

--Robert





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

Date: 05 Mar 2001 16:21:41 -0800
From: Gerard Lanois <gerard@NOSPAMlanois.com>
Subject: Re: libnet and Net::SMTP config.pm is wrong
Message-Id: <usnkrd9wq.fsf@NOSPAMlanois.com>

Jon Ericson <Jonathan.L.Ericson@jpl.nasa.gov> writes:

> Alan Pettigrew <alan1.pettigrew1@fox1-europe1.com> writes:
> 
> > I have just installed libnet (1.06) with PPM on 2 NT machines.
> 
> CPAN has libnet-1.0703.tar.gz that seems to fix the problem you
> mentioned.  It seems reasonable to expect whoever provided the PPM to
> upgrade the package.  Alternativly, you could get and install the
> package directly from CPAN.  (You may need make (or nmake from
> Microsoft), but I don't think you need a C compiler.

You DO NOT need a C compiler to install libnet from the .tar.gz.

-Gerard
http://www.lanois.com/perl/





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

Date: Mon, 05 Mar 2001 23:08:55 +0000
From: W Scott Joynes <wayne@joynes.fsbusiness.co.uk>
Subject: Re: Magic Marker
Message-Id: <3AA41C87.DB738DBA@joynes.fsbusiness.co.uk>

"Public " wrote:

> W Scott Joynes <wayne@joynes.fsbusiness.co.uk> wrote:
>
> >Why am I getting so wound up.............. ?
>
> cuz yer a fucken idiot who thinks he's the cops?
>
> HTH
>
> ---
> This message did not originate from the Sender address above.
> It was posted with the use of anonymizing software at
> http://anon.xg.nu
> ---

Your name ain't Z by any chance is it. [I'm biting, I'm biting ]




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

Date: Mon, 5 Mar 2001 18:38:49 -0600
From: "Public <Anonymous_Account>" <remailer@anon.xg.nu>
Subject: Re: Magic Marker
Message-Id: <75c1cf17f212e0a49c617c7bef7e616f@anon.xg.nu>

W Scott Joynes <wayne@joynes.fsbusiness.co.uk> wrote:

>Your name ain't Z by any chance is it. [I'm biting, I'm biting ]

Nope, wrong end the alphabet: it's Al.
Not only did I invent the Internet, but I am the 



---
This message did not originate from the Sender address above.
It was posted with the use of anonymizing software at 
http://anon.xg.nu
---




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

Date: Tue, 6 Mar 2001 12:27:17 +1100
From: "Iain Hosking" <iain_hosking@hotmail.com>
Subject: Opening files on other Windows machines
Message-Id: <981edl$7lg$1@thebe.syd.dav.net.au>

How do I open a file on another Windows machine?

I can't use a drive mapping as this is a CGI script and it's running in the
system account.

Microsoft's \\machine\drive\foo\bar syntax doesn't work.

I'm using ActiveState Perl 5.6.0 (build 623).

Thanks

Iain




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

Date: Tue, 06 Mar 2001 00:25:31 GMT
From: "Parrot" <parrot0123@yahoo.ca>
Subject: Re: Perl, Cookies, and Apache.
Message-Id: <%7Wo6.377005$JT5.11984295@news20.bellglobal.com>


Chris Stith <mischief@velma.motion.net> wrote in message
news:ta83nb89me0553@corp.supernews.com...
> Mark W. Schumann <catfood@apk.net> wrote:
>
> Telling someone that a question is off-topic is not a flame. If you think
> that's a flame, then you've never been flamed.
>
Okay, maybe a flame would be an exageration for what he said.  However, the
message was extremely hostile, much more so than necessary.  Plus, my
comment was geared to other observations that I've made as well where
posters are violently slammed for the smallest thing.

> Maybe this is too far the other way. I'd say it'd be good for someone
> who just posted off-topic to post "Sorry for being off-topic. I'll try
> to make sure my next post s on-topic."

Thing is, I really wasn't far off topic.  I wanted to know if the problem I
was experiencing was a result of Perl being mis-configured for my server.
Even though it was my server that was misconfigured, my question DID have to
do with Perl and I'd say it was appropriate for this newsgroup.

Of course, if somebody still felt that my post was off-topic, hostile
messages like that are not going to give me much incentive to apologise.

> A hypochondriac at a general practitioner's office is one thing. Someone
> with a head trauma going to a cardiologist is another. Referrals to other
> places is common practice.

Of course they are - and if a certain question could be answered better
somewhere else, a good referral would be the perfect way to help.  Wouldn't
that be better than hostile, condescending replies?

> True, and saying a post is off-topic is not cruel or unhelpful. If a
person
> is posting off-topic posts, it is often a sign that they do not understand
> the problem or the nature of the tools being used. Pointing out someone's
> mistake holds a great potential to help.

Now there's one thing that I can agree with.  Don't think that I'm against
pointing out somebody's mistakes, that's how people learn.  What I'm against
is the way some people get violently OFFENDED at such minor posts.

> A little off topic is one thing. Some people consider this to be the place
> for CGI questions, database questions, web server configuration questions,
> FTP questions, sendmail questions, shell questions, and many others. If
> you gladly help with off-topic posts, you get more of them. The more of
them
> you get in the group, the less helpful the group is as a source of
information
> on its givven topic. This principle is exactly why there's not one big
group
> called usenet.the  --  and is also why comp.lang.perl was split into
> comp.lang.perl.misc, comp.lang.perl.moderated, comp.lang.perl.modules, and
> comp.lang.perl.tk (and no longer exists as its own group). If we wanted
all
> of the computer related questions in one group, the comp heirarchy would
> be one huge unmanageable mess under the name `comp.misc'.

CGI?  Database?  Sendmail?  Heck, these are all related to Perl if the
question is "How do I do it in Perl?"  This programming language covers a
lot of area you know.





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

Date: Tue, 06 Mar 2001 01:38:59 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: perl-ize and optimize
Message-Id: <3AA44117.4838C1F@acm.org>

Ren Maddox wrote:
> 
> On Mon, 05 Mar 2001, krahnj@acm.org wrote:
> 
> > "Charles K. Clarkson" wrote:
> >>     my $string = shift; $string =~ s/^(\w+?)\s(.+)$/$2 $1/ for 0
> >>     .. rand 1 + $string =~ tr/ //s;
> >
> > Try it with this sentence and see how even the distribution is. :-)
> >
> > print shuffle( q{I calculated O'Brian's pay at $15.00 per hour.} ),
> > "\n";
> 
> I assume you're just pointing out that the "\w" really should be "\S",
> correct?

Yes.


John


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

Date: Tue, 06 Mar 2001 13:25:37 +1300
From: "Adam Warner" <usenet@consulting.net.nz>
Subject: Regex question (newbie)
Message-Id: <20010306.132446.1186452551.12090@consulting.net.nz>

Hi all,

I understand the "BASIC" way of operating on strings. But I want to use a
regular expression to modify a string and I can't quite formulate an
elegant solution.

Take the string $_. All I want to do is place a regular expression
"template" or "filter" over that string and put the result into another
string (say $a).  

I just can't get the syntax right. For example:

$_ = "this, is a test";
$a = /.*,/;

$a returns 1 because it is true that a comma appears in $_.

How can I tell Perl to give me the result of the match (like grep)? In
other words I want $a to contain "this," (and later work out how to make
the match non-greedy).

Many thanks,
Adam


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

Date: Tue, 06 Mar 2001 00:43:24 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regex question (newbie)
Message-Id: <slrn9a89gs.5vl.tadmc@tadmc26.august.net>

Adam Warner <usenet@consulting.net.nz> wrote:
>
>I just can't get the syntax right. For example:
>
>$_ = "this, is a test";
>$a = /.*,/;
>
>$a returns 1 because it is true that a comma appears in $_.
>
>How can I tell Perl to give me the result of the match (like grep)? In
>other words I want $a to contain "this," 


That isn't "like grep" (neither one of the grep's in fact).

grep(1) returns lines that match the pattern, not the part of
the string that matched the pattern.

grep() returns list elements that match the pattern, not the part 
of the string that matched the pattern.

Perl can easily act like a not-grep as you describe:

   my $a = $1 if /(.*,)/;


>(and later work out how to make
>the match non-greedy).

   my $a = $1 if /(.*?,)/;


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


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

Date: Tue, 06 Mar 2001 14:41:23 +1300
From: "Adam Warner" <usenet@consulting.net.nz>
Subject: Re: Regex question (newbie)
Message-Id: <20010306.144123.601385644.12303@consulting.net.nz>

Thanks Tad,

> Perl can easily act like a not-grep as you describe:
> 
>    my $a = $1 if /(.*,)/;
> 
> 
>>(and later work out how to make
>>the match non-greedy).
> 
>    my $a = $1 if /(.*?,)/;

That's great! Sorry I was confusing the way matches are found using
regular expressions and what grep outputs. That's why the newbie alert
was there :-)

Full steam ahead now though.

Regards,
Adam


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

Date: Mon, 05 Mar 2001 15:10:39 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regexp and parenthesis ...
Message-Id: <3AA41CEF.477CFC19@stomp.stomp.tokyo>

Ren Maddox wrote:

(snipped)

> If you're willing to use experimental features, then perlre(1) has an
> example of how to match a balanced parenthetical expression.  Using
> that as a starting point, this isn't too difficult.
 
> Here it is:

(snipped code) 

> Works like a champ!


Interesting method although exceptionally inefficient
running an average of eight to ten times as slow as
comparable index and substring methodology.


Godzilla!
--

TEST SCRIPT:
____________


#!perl

print "Content-type: text/plain\n\n";

use Benchmark;

print "Run One:\n\n";
&Time;

print "\n\nRun Two:\n\n";
&Time;

print "\n\nRun Three:\n\n";
&Time;


sub Time
 {
  timethese (100000,
   {

   'name1' =>
   '$string = "foo(bar(b)az)|";
    $re = qr{\((?:(?> [^()]+ )|(??{ $re }))*\)}x;
    if ($string =~ /(.*)($re)\|/)
     { $one = $1; $two = $2; }',

   'name2' =>
   '$string = "foo(bar(b)az)|";
    chop ($string);
    $one = substr ($string, 0, index ($string, "("), "");
    $two = $string;',

   'name3' =>
   '$string = "foo(bar)(baz)|";
    $re = qr{\((?:(?> [^()]+ )|(??{ $re }))*\)}x;
    if ($string =~ /(.*)($re)\|/)
     { $one = $1; $two = $2; }',

   'name4' =>
   '$string = "foo(bar)(baz)|";
    chop ($string);
    $one = substr ($string, 0, index ($string, ")(") + 1, "");
    $two = $string;',

   } );
 }

exit;

PRINTED RESULTS:
________________

Run One:

Benchmark: timing 100000 iterations of name1, name2, name3, name4...
 name1:  6 wallclock secs ( 6.38 usr +  0.00 sys =  6.38 CPU) @ 15673.98/s 
 name2: -1 wallclock secs ( 0.60 usr +  0.00 sys =  0.60 CPU) @ 166666.67/s 
 name3:  5 wallclock secs ( 4.83 usr +  0.00 sys =  4.83 CPU) @ 20703.93/s 
 name4:  1 wallclock secs ( 0.66 usr +  0.00 sys =  0.66 CPU) @ 151515.15/s 


Run Two:

Benchmark: timing 100000 iterations of name1, name2, name3, name4...
 name1:  7 wallclock secs ( 6.54 usr +  0.00 sys =  6.54 CPU) @ 15290.52/s 
 name2:  1 wallclock secs ( 0.60 usr +  0.00 sys =  0.60 CPU) @ 166666.67/s 
 name3:  5 wallclock secs ( 4.89 usr +  0.00 sys =  4.89 CPU) @ 20449.90/s 
 name4:  1 wallclock secs ( 0.65 usr +  0.00 sys =  0.65 CPU) @ 153846.15/s 


Run Three:

Benchmark: timing 100000 iterations of name1, name2, name3, name4...
 name1:  6 wallclock secs ( 6.48 usr +  0.00 sys =  6.48 CPU) @ 15432.10/s 
 name2:  0 wallclock secs ( 0.66 usr +  0.00 sys =  0.66 CPU) @ 151515.15/s 
 name3:  5 wallclock secs ( 4.89 usr +  0.00 sys =  4.89 CPU) @ 20449.90/s 
 name4:  0 wallclock secs ( 0.66 usr +  0.00 sys =  0.66 CPU) @ 151515.15/s


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

Date: 05 Mar 2001 17:29:34 -0600
From: Ren Maddox <ren@tivoli.com>
Subject: Re: regexp and parenthesis ...
Message-Id: <m3ae6zdcbl.fsf@dhcp9-175.support.tivoli.com>

On Mon, 05 Mar 2001, godzilla@stomp.stomp.tokyo wrote:

> Interesting method although exceptionally inefficient
> running an average of eight to ten times as slow as
> comparable index and substring methodology.

Certainly.  But then again, you had to modify your index string to
match your input string, which isn't really fair.  The whole point is
that finding balanced parentheses is hard.  The index method simply
doesn't cut it.

-- 
Ren Maddox
ren@tivoli.com


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

Date: Mon, 05 Mar 2001 17:01:29 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regexp and parenthesis ...
Message-Id: <3AA436E9.47E7DB06@stomp.stomp.tokyo>

Ren Maddox wrote:
 
> Godzilla! wrote:
 
> > Interesting method although exceptionally inefficient
> > running an average of eight to ten times as slow as
> > comparable index and substring methodology.
 
> Certainly.  But then again, you had to modify your index string to
> match your input string, which isn't really fair.  The whole point is
> that finding balanced parentheses is hard.  The index method simply
> doesn't cut it.


             ( )
   ==\  __ __[oo
      \/     /\@
  ##   l_____|
 ####   ll  ll
######  LL  LL



Godzilla!
-- 
@ø=(a .. z);@Ø=qw(6 14 3 25 8 11 11 0 17 14 2 10 18);
$§="\n";$ß="\b";undef$©;print$§x($Ø[4]/2);
for($¡=0;$¡<=$Ø[2];$¡++){foreach$¶(@Ø){
$ø[$¶]=~tr/A-Z/a-z/;if(($¡==1)||($¡==$Ø[2]))
{$ø[$¶]=~tr/a-z/A-Z/;}print$ø[$¶];if($¶==0)
{print" ";}if($¶==$Ø[12]){print" !";}&D;}
print$ßx($Ø[4]*2);}print$§x($Ø[10]*2);
sub D{select$©,$©,$©,.25;}exit;


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

Date: Tue, 06 Mar 2001 00:04:28 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Small problem: dup'ing DATA and $.
Message-Id: <gQVo6.28631$W05.6101224@news1.rdc1.mi.home.com>

I was tinkering with $. and the DATA filehandle, and ran into this small
problem.  Look at the code:

# Not work
open(FOO, "<&DATA") || die;
$_=<DATA>;
if ($a=<FOO>) { 
        print "read ok\n";
} else { 
        print "not ok: $!\n";
}
__END__
BLAH
HLAG
NARF
POIT

What SHOULD happen (IMHO) is that I dup DATA, read a line from DATA into
$_ ("BLAH\n") and then read a line from FOO into $a (I'd take either "HLAG\n"
or "BLAH\n" at this point :)  

But $a=<FOO> fails, and the "not ok" branch is taken.  Worse, $! isn't
set to anything useful.  Did these tired eyes miss something obvious?

-- 
    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: 6 Mar 2001 01:35:25 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: Submitting Forms from Code
Message-Id: <981est$2pv$1@216.155.32.13>

In article <comdog-C7BE08.18391104032001@news.panix.com>, brian d foy 
<comdog@panix.com> wrote:

 | > brian d foy's response was correct. He usually is about things in this
 | > area.
 | 
 | i think i need to expand my perceived "area". :)

Just watch out for those Intellectual Property Tax Collectors if you 
plan on expanding your perceptions[1] any.

hehehe :) 

[1] not to mention carefully memorizing which direction is 'down' :D

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: 6 Mar 2001 01:54:56 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: Uploading a file
Message-Id: <981g1g$9sf$0@216.155.32.13>

In article <v7no6.212$mU5.9428@eagle.america.net>, garry@zvolve.com 
(Garry Williams) wrote:

 | Maybe you're both right.  
 | 
 | Question one: What does the string "test\n" contain?  
 | 
 | On a Windows machine:
 |   $ uname -a
 |   MS-DOS VFR 7 10 pc
 |   $ perl -wle 'print map { " " . ord } split //, "test\n"'
 |    116 101 115 116 10
 |   $
 | 
 | On a Unix machine: 
 |   $ uname -a
 |   SunOS zweb 5.7 Generic_106541-11 sun4u sparc SUNW,Ultra-60
 |   $ perl -wle 'print map { " " . ord } split //, "test\n"'
 |    116 101 115 116 10
 |   $ 
 | 
 | Hmm.  No difference.  In other words, "\n" is _always_ interpolated as
 | the ASCII newline character no matter what the OS or hardware.  

On a Macintosh
  Software overview
        Finder/System: 8.6 US
        Perl         : 5.004
   Hardware overview
    Built-in memory:    216 MB
    Processor info:     PowerPC G3 400 MHz 

#!perl -wl
print map { " " . ord } split //, "test\n"

 116 101 115 116 13

Gee, that *does* seem to look different.. perhaps it isn't as universal 
as would appear at first glance. *head scratching*

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Tue, 06 Mar 2001 01:14:51 GMT
From: David Bakhash <cadet@alum.mit.edu>
Subject: use strict (vars, etc.)
Message-Id: <m38zmkw4i1.fsf@alum.mit.edu>

Hi,

I'm having some trouble with:

use strict

especially with respect to variables.

I have the simple situation.  I want to define a function which, when
called, will be done in an environment where some dynamic variables
will be defined (i.e. with local()).  But I do want to make Perl
require me to declare these as such in my function.  Can someone tell
me if this is right:

sub function_1 {
 local $arg_1 = shift();
 function_2();
}

sub function_2 {
 our($arg_1); # since this executes in that dynamic extent
 my $arg_2 = shift();
 print "arg 1 and arg 2 are $arg_1 and $arg_2.\n";
}

That's what I think is right.

I'm now getting some package errors like:

==> Error: Global symbol "$arg_1" requires explicit package name

At the top of the file there is a package statement:

package MyPackage;

What's missing?

dave

 


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

Date: Tue, 06 Mar 2001 01:43:19 GMT
From: "Dave Brondsema" <brondsema@my-deja.com>
Subject: Re: use strict (vars, etc.)
Message-Id: <XgXo6.28937$W05.6162715@news1.rdc1.mi.home.com>


"David Bakhash" <cadet@alum.mit.edu> wrote in message
news:m38zmkw4i1.fsf@alum.mit.edu...
> Hi,
>
> I'm having some trouble with:
>
> use strict
>
> especially with respect to variables.
>
> I have the simple situation.  I want to define a function which, when
> called, will be done in an environment where some dynamic variables
> will be defined (i.e. with local()).  But I do want to make Perl
> require me to declare these as such in my function.  Can someone tell
> me if this is right:
>
> sub function_1 {
>  local $arg_1 = shift();
>  function_2();
> }
>
> sub function_2 {
>  our($arg_1); # since this executes in that dynamic extent
>  my $arg_2 = shift();
>  print "arg 1 and arg 2 are $arg_1 and $arg_2.\n";
> }
>
> That's what I think is right.
>
> I'm now getting some package errors like:
>
> ==> Error: Global symbol "$arg_1" requires explicit package name
>
> At the top of the file there is a package statement:
>
> package MyPackage;
>
> What's missing?
>

I recall reading in some perl docs that local doesn't do what is expected.
Use 'my' instead; for more info look for the documentation on local (sorry,
i'm too lazy right now to point you to it)


> dave
>
>

dave




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

Date: Tue, 06 Mar 2001 01:53:43 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: use strict (vars, etc.)
Message-Id: <3AA44423.EB1A9A6E@rochester.rr.com>

David Bakhash wrote:
 ...
> I'm having some trouble with:
> 
> use strict
> 
> especially with respect to variables.
> 
> I have the simple situation.  I want to define a function which, when
> called, will be done in an environment where some dynamic variables
> will be defined (i.e. with local()).  But I do want to make Perl
> require me to declare these as such in my function.  Can someone tell
> me if this is right:
> 
> sub function_1 {
>  local $arg_1 = shift();
>  function_2();
> }
> 
> sub function_2 {
>  our($arg_1); # since this executes in that dynamic extent
>  my $arg_2 = shift();
>  print "arg 1 and arg 2 are $arg_1 and $arg_2.\n";
> }
> 
> That's what I think is right.
> 
> I'm now getting some package errors like:
> 
> ==> Error: Global symbol "$arg_1" requires explicit package name
> 
> At the top of the file there is a package statement:
> 
> package MyPackage;
> 
> What's missing?
> 
> dave
> 
> 

The error message states it clearly:  "Global symbol "$arg_1" requires
explicit package name".  Put:

    use vars '$arg_1';

near the start of your package and you'll be all set.  Just because a
package global is only used in local statement doesn't make the
requirement to declare it any different than any other package global. 
But you can't declare it with:

    my $arg_1;

because then it will be a lexcial variable, not a package global, and a
lexical variable can't be used with local.  Therefore, use vars.  HTH.
-- 
Bob Walton


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

Date: Tue, 06 Mar 2001 01:35:48 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: why won't "format FILEHANDLE" work??
Message-Id: <3AA44053.CFC2EBFD@acm.org>

David Charles wrote:
> 
> Hello,
> 
> I am trying to write a script to take an input file, and format the output
> for printing reports.  I have rather limited knowledge of perl so far, but I
> thought that the best way to do it would be using "format" (if anyone has
> any better ideas, please enlighten me).  I am using the following code:
> 
> --==START OF CODE SNIPPET==--
> $answer = "n";
> while ($answer ne "y") {
>  system('cls');
>  print "Please enter the series: ";
>  $series_name = <STDIN>;
>  chomp($series_name);
>  $series_name = uc($series_name);

chomp( $series_name = lc substr <STDIN>, 0, 1 );

>  print "You entered Series: $series_name\n";
>  print "Press \"Y\" if this correct, or any other key to reenter the series:
> ";
>  $answer = <STDIN>;
>  chomp($answer);
>  $answer = lc($answer);

chomp( $answer = lc substr <STDIN>, 0, 1 );

> }
> 
> open SERIES, "<d:\\aReport\\$series_name.txt" or die "Can't open
> $series_name data file: $!";
> 
> while (<SERIES>) {
>  ($style, @inventory) = split(/;/, $_);
>  foreach $num (@inventory) {
>   $dat{$style} = "$dat{$style}\n$num";

$dat{$style} = "\n" . join "\n", @inventory;

>  }
>  print $style.$dat{$style};
> }
> sort keys %dat;

Sort is used in a void context here. In other words, sorting the keys of
%dat does not change %dat.


> 
> $ctime = localtime(time);
> 
> open REPORT, ">d:\\aReport\\print$series_name.txt" or die "Can't create
> report: $!";
> 
> format REPORT_TOP =
> #2345678901234567890123456789012345678901234567890123456789012345
> @<<<<<<<<<<<<<<<<<<<<<<<<    @|||||       Page: @>>>>>
> $ctime,       $series_name,      $%
> -----------------------------------------------------------------
> .
> format REPORT =
> @||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
> { while (($key, $val) = each %dat)
>  { $key,"\n",$val }
> }

If you want this sorted by %dat's keys you need to do something like:
{ foreach my $key ( sort keys %dat )
    { $key, "\n", $dat{$key} }
}

> .
> $^ = REPORT_TOP;
> $~ = REPORT;
> write;

write REPORT;

> close outREPORT;

close REPORT;

> --==END OF CODE SNIPPET==--
> for whatever reason (probably that I just don't understand the use of
> "format"), the file that it should be writing to is always empty.  I tried
> writing to STDIN, which still gave no results.  Can someone PLEASE help
> me????


John


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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


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