[25651] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 7893 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Mar 17 18:10:26 2005

Date: Thu, 17 Mar 2005 15:10:18 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 17 Mar 2005     Volume: 10 Number: 7893

Today's topics:
    Re: Random String Generator <dummymb@hotmail.com>
    Re: Random String Generator <1usa@llenroc.ude.invalid>
    Re: Random String Generator <kkeller-usenet@wombat.san-francisco.ca.us>
    Re: Random String Generator <Im.so.HuckinFappy@spamgourmet.com>
    Re: Random String Generator <spamtrap@dot-app.org>
        regex problem -- capturing variables <tickfigure@hotmail.com>
    Re: regex problem -- capturing variables <mritty@gmail.com>
    Re: regex problem -- capturing variables <noreply@gunnar.cc>
        Stumped by eval and scoping problem <shanker.neelakantan@gmail.com>
    Re: Stumped by eval and scoping problem <shanker.neelakantan@gmail.com>
    Re: Weird HTTP heders in Html Body <matternc@comcast.net>
    Re: Weird HTTP heders in Html Body c_klar@c-cs.com
    Re: Weird HTTP heders in Html Body <matternc@comcast.net>
    Re: Weird HTTP heders in Html Body <1usa@llenroc.ude.invalid>
    Re: Weird HTTP heders in Html Body <noreply@gunnar.cc>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 17 Mar 2005 12:08:55 -0800
From: "DMB" <dummymb@hotmail.com>
Subject: Re: Random String Generator
Message-Id: <1111090135.855962.176190@g14g2000cwa.googlegroups.com>

Isn't it obvious?  I didn't post randomly within the thread.  I
specifically posted a response to Fabian Pilkowski's post.  Had I meant
that more than just his suggestion was good, I would have listed them
specifically.  If you are having a conversation with 4 people and one
looks at you directly and tells you something, then you respond with
"that's cool", doesn't it seem logical that your response was to his
statement and not to something that one of the other 3 stated earlier.

Anyway, it's not a big deal.  I was justing posting a quick memo to let
Fabian know that I appreciated his suggestion.  My post didn't add any
value to the thread other than that, so I didn't see any reason to be
thorough.



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

Date: Thu, 17 Mar 2005 20:17:06 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Random String Generator
Message-Id: <Xns961C9B7D311E0asu1cornelledu@127.0.0.1>

"DMB" <dummymb@hotmail.com> wrote in news:1111090135.855962.176190
@g14g2000cwa.googlegroups.com:

> Isn't it obvious?

Isn't what obvious?

> Anyway, it's not a big deal. 

"It", i.e. not composing your follow-ups, is a big deal.

> My post didn't add any value to the thread 

Precisely.

Sinan


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

Date: Thu, 17 Mar 2005 12:58:50 -0800
From: Keith Keller <kkeller-usenet@wombat.san-francisco.ca.us>
Subject: Re: Random String Generator
Message-Id: <pl7pg2xp0b.ln2@goaway.wombat.san-francisco.ca.us>

On 2005-03-17, DMB <dummymb@hotmail.com> wrote:
> Isn't it obvious?

No, it's not.

> I didn't post randomly within the thread.  I
> specifically posted a response to Fabian Pilkowski's post.

That's not immediately obvious from your post.  One has to
retrieve the parent post in order to figure out to whom you
were responding.

> If you are having a conversation with 4 people and one
> looks at you directly and tells you something, then you respond with
> "that's cool", doesn't it seem logical that your response was to his
> statement and not to something that one of the other 3 stated earlier.

It's perfectly logical.  But you're not having a conversation, you're
posting to usenet.

Consider: your "thank you" could arrive at my news server *after* some
or all of the posts which chronologically came before yours.  Or, my
news server could receive three more posts before it gets yours.
Now how do I know to whom you're responding?  (I need to retrieve
the parent post, and then have to hope that you picked that particular
post to followup for a reason.)

> Anyway, it's not a big deal.  I was justing posting a quick memo to let
> Fabian know that I appreciated his suggestion.  My post didn't add any
> value to the thread other than that, so I didn't see any reason to be
> thorough.

So, now you know that you need to be thorough, because the way you
currently followup leaves too much ambiguity.  Please quote at least
*some* relevant context next time.

--keith

-- 
kkeller-usenet@wombat.san-francisco.ca.us
(try just my userid to email me)
AOLSFAQ=http://wombat.san-francisco.ca.us/cgi-bin/fom
see X- headers for PGP signature information



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

Date: Thu, 17 Mar 2005 13:45:49 -0700
From: Jeff <Im.so.HuckinFappy@spamgourmet.com>
Subject: Re: Random String Generator
Message-Id: <d1cq9u$2ea4@xco-news.xilinx.com>

DMB wrote:
> Isn't it obvious?  

Whatever 'it' is, I guess not, since I have no idea what you're talking 
about.

> I didn't post randomly within the thread.

This is posted randomly in a thread, so I'll assume you have done so 
before and you will do so again.  Are you under the impression that when 
reading newsgroups, everyone sees *all* the messages?  Many (most?) 
people only see new messages, and it is the responsibility of posters to 
provide enough context within their message to make them coherent

> I specifically posted a response to Fabian Pilkowski's post.

Which somone would know exactly how?

> Had I meant
> that more than just his suggestion was good, I would have listed them
> specifically.  If you are having a conversation with 4 people and one
> looks at you directly and tells you something, then you respond with
> "that's cool", doesn't it seem logical that your response was to his
> statement and not to something that one of the other 3 stated earlier.

Nope.  Sometimes I've gotten lost in thought for a couple of minutes, 
and I'm responding to what someone said a few minutes ago.  And posting 
on Usenet is not like speaking to people in person anyway.  In the 
absence of body language, facial expressions, subtlety of vocal 
inflection, and time continuity, it's much more important to make 
yourself clear and easily understood.

> Anyway, it's not a big deal.

I guess if you don't want anyone to know what you're talking about, it 
isn't.

> I was justing posting a quick memo to let
> Fabian know that I appreciated his suggestion.  My post didn't add any
> value to the thread other than that, so I didn't see any reason to be
> thorough.

If you consistently demonstrate you are not thorough, and you don't 
follow established posting guidelines, people will stop reading your 
messages.  Whether that is a good enough reason to be thorough is your 
own decision to make.

~Jeff


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

Date: Thu, 17 Mar 2005 16:25:20 -0500
From: Sherm Pendley <spamtrap@dot-app.org>
Subject: Re: Random String Generator
Message-Id: <BrmdnXKq5PJeaKTfRVn-tg@adelphia.com>

DMB wrote:

> Isn't it obvious?

Isn't *what* obvious?

Some context in your replies, please. Not everyone has the patience to sort
through a pile of old messages just to figure out which one you're replying
to.

Have you read the posting guidelines for this group?

sherm--

-- 
Cocoa programming in Perl: http://camelbones.sourceforge.net
Hire me! My resume: http://www.dot-app.org


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

Date: Thu, 17 Mar 2005 19:25:46 +0100
From: tickfigure <tickfigure@hotmail.com>
Subject: regex problem -- capturing variables
Message-Id: <opsnsn48ojm79xgb@t-offline.de>

Hello,

I've inherited some code and have to make a few changes.  I'm sure this is  
not the way to go about this.... Hopefully someone can help me.

I'm trying to generate the number of "captures" (variables $1, $2, etc.)  
of a regex dynamically. I don't know how many are required. I've included  
a small example below, so it is hopefully easier to understand.

Thanks for any help!

tick



#! /usr/bin/perl

use strict;
my %caphash = (
      test1 => {
       a => "1",
       b => "1",
       c => "1",
      },
      test2 => {
       a => "1",
       b => "1",
       c => "1",
      }
);

my %hashresult;
my %hash1;
my $string = "another string here";

my $pattern = '(\S+)\s+(\S+)\s+(\S+)';
my $caps = 3; # Because there are three capturing parenths in $pattern.   
This variable
                # exists purely for this example.

foreach my $ele (keys %caphash) { # foreach no.1
     my $test = $caphash{$ele};
     %hash1 = %$test;

     foreach my $ele2 (keys %hash1) { # foreach no.2

     # Here lies the problem.. since $pattern will change after each
     # complete iteration of foreach no.1, the number of "captures" will  
also change.
     # (I have only included 1 pattern for the example.)
     # How can I dynamically create the $1, $2, variables so that no
     # matter how many "captures" the values will be inserted into the hash
     # properly?


      # This obviously does not work.
        for (my $x = 1; $x <= $caps; $x++) {
            $string =~ /$pattern/;
	  $hashresult{$ele}{$ele2} = $x;
        }
     }
}
print "End\n";


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

Date: Thu, 17 Mar 2005 19:31:06 GMT
From: "Paul Lalli" <mritty@gmail.com>
Subject: Re: regex problem -- capturing variables
Message-Id: <_Vk_d.7751$qN3.611@trndny01>

"tickfigure" <tickfigure@hotmail.com> wrote in message
news:opsnsn48ojm79xgb@t-offline.de...
> Hello,
>
> I've inherited some code and have to make a few changes.  I'm sure
this is
> not the way to go about this.... Hopefully someone can help me.
>
> I'm trying to generate the number of "captures" (variables $1, $2,
etc.)
> of a regex dynamically.

A pattern match in list context returns a list of all captures.  Is this
what you're looking for?

my @caps = 'foo bar baz' =~ /(\w)(\w+)\s(\w+)/;
# @caps contains ('f', 'oo', 'bar')


> I don't know how many are required. I've included
> a small example below, so it is hopefully easier to understand.
>
>
> #! /usr/bin/perl
>
> use strict;

you forgot
use warnings;

> my %caphash = (
>       test1 => {
>        a => "1",
>        b => "1",
>        c => "1",
>       },
>       test2 => {
>        a => "1",
>        b => "1",
>        c => "1",
>       }
> );
>
> my %hashresult;
> my %hash1;
> my $string = "another string here";
>
> my $pattern = '(\S+)\s+(\S+)\s+(\S+)';
> my $caps = 3; # Because there are three capturing parenths in
$pattern.
> This variable
>                 # exists purely for this example.
>
> foreach my $ele (keys %caphash) { # foreach no.1
>      my $test = $caphash{$ele};
>      %hash1 = %$test;

 ...ew.

while my ($key, $href) = each %caphash) {
  my %hash1 = %$href;

>
>      foreach my $ele2 (keys %hash1) { # foreach no.2
>
>      # Here lies the problem.. since $pattern will change after each
>      # complete iteration of foreach no.1, the number of "captures"
will
> also change.
>      # (I have only included 1 pattern for the example.)
>      # How can I dynamically create the $1, $2, variables so that no
>      # matter how many "captures" the values will be inserted into the
hash
>      # properly?

I really have no idea what you're getting at here.  How will $pattern be
changing?  If that's the central issue, why did you make a test program
in which $pattern doesn't change?!

>
>
>       # This obviously does not work.

I don't doubt that, but you haven't explained what constitutes "working"
in this case.  What is your desired result?  How should the finished
%hashresult be structured?

>         for (my $x = 1; $x <= $caps; $x++) {
>             $string =~ /$pattern/;
>   $hashresult{$ele}{$ele2} = $x;

My only guess is to go back to what I said originally.  Do the pattern
match in list context, and use the list of resulting captures.  Without
knowing more about your actual goal, it's difficult to be more precise
than that.

>         }
>      }
> }
> print "End\n";


Paul Lalli



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

Date: Thu, 17 Mar 2005 20:38:11 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: regex problem -- capturing variables
Message-Id: <39u4rbF692ujlU1@individual.net>

tickfigure wrote:
> I'm trying to generate the number of "captures" (variables $1, $2, 
> etc.)  of a regex dynamically. I don't know how many are required. I've 
> included  a small example below, so it is hopefully easier to understand.

Well, the example didn't make it easier for me to understand. :)

Maybe this code might point you in the right direction:

     my $string = 'another string here';
     my $pattern = '(\S+)\s+(\S+)\s+(\S+)';
     my @capvalues = $string =~ /$pattern/;
     print '@capvalues: ', join(', ', @capvalues), "\n";
     print 'Number of captures: ', scalar @capvalues, "\n";

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 17 Mar 2005 13:55:20 -0800
From: "shanx" <shanker.neelakantan@gmail.com>
Subject: Stumped by eval and scoping problem
Message-Id: <1111096520.079438.61460@g14g2000cwa.googlegroups.com>

I am not a perl newbie, but I am really stumped by this eval problem.
I cannot change a lot of the existing code since it is legacy stuff, so
any solution to redo this in a totally different manner won't work for
me.

The Problem:

A perl program called bug_find includes a test-suite library called
foo.pl using 'do'. bug_find has 'use strict' declaration and it passes
a perl -c, (we're using perl 5.6), but foo.pl doesn't have a 'use
strict' declaration. The relevant parts of the code from both files are
shown below:

####bug_find####
 ..
sub run_test {
    my ($ref) = @_;

    my $command = $ref->{cmd};
    local $results = {};

    open(FH, "$command 2>&1 |") or die $!;

    my @output = <FH>;
    $results->{output} = @output;

    if (exists($ref->{post}) and defined($ref->{post}) {
        eval $ref->{post};
    }

    return $results;
}

 ..

# What follows is main part of bug_find.
{
do $suite;  # let us say $suite is foo.pl

foreach $i (@tests) {
     $result = run_test($i);
}
}

####end of bug_find####


####start of foo.pl (or whatever $suite is)####


@specific_tests = (
    {
       'cmd'   =>   "cleartool $blah $blah", # This is some shell
command
       'post'  =>   "$gotit = $1 if ($results->{output} =~ m/success
(\w+)/); print \"Value of gotit is $gotit\n\"",
    },
    {
       'cmd'   =>   'cd /var/tmp/$gotit; ./do_something.sh',
    }
);

@tests = (@specific_tests);

###end of foo.pl####

Note that the variable @tests in foo.pl is being used by bug_find after
'do'.

My problem is that when I run bug_find, I see the correct value of
$gotit in the print statement but when I try to read the value of
$gotit (just before do_something.sh), the variable seems to be unset
and it is empty.

What is going on? 

-Shanker



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

Date: 17 Mar 2005 14:06:36 -0800
From: "shanx" <shanker.neelakantan@gmail.com>
Subject: Re: Stumped by eval and scoping problem
Message-Id: <1111097196.022972.26340@g14g2000cwa.googlegroups.com>

Let me correct a little typo.
 ..
{
       'cmd'   =>   "cd /var/tmp/$gotit; ./do_something.sh",
 } 
 ..
The hash value is within double quotes, not single quotes.



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

Date: Thu, 17 Mar 2005 16:57:46 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Weird HTTP heders in Html Body
Message-Id: <B6-dnWfaPZbHYKTfRVn-gA@comcast.com>

c_klar@c-cs.com wrote:

> HI,
> 
> When running the following script on certain web browsers in displays
> HTTP headers in the body of the page.
> 
> _______________________
> TestPerl.pl:
> - - - - - -
> print("HTTP/1.0 200 OK\n");
> print("Content-type: text/html\n\n");
> 
> print "a" x 2000;

That's not legal HTML.  You throw any old crap at the browser,
you get any old crap back.


-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: 17 Mar 2005 14:10:44 -0800
From: c_klar@c-cs.com
Subject: Re: Weird HTTP heders in Html Body
Message-Id: <1111097444.539000.295690@l41g2000cwc.googlegroups.com>

O' Please,



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

Date: Thu, 17 Mar 2005 17:14:03 -0500
From: Chris Mattern <matternc@comcast.net>
Subject: Re: Weird HTTP heders in Html Body
Message-Id: <IL6dnaH6E762nKffRVn-hA@comcast.com>

c_klar@c-cs.com wrote:

> O' Please,

"O' Please," what?  Garbage in, garbage out.

-- 
             Christopher Mattern

"Which one you figure tracked us?"
"The ugly one, sir."
"...Could you be more specific?"


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

Date: Thu, 17 Mar 2005 22:19:02 GMT
From: "A. Sinan Unur" <1usa@llenroc.ude.invalid>
Subject: Re: Weird HTTP heders in Html Body
Message-Id: <Xns961CB0296E587asu1cornelledu@127.0.0.1>

c_klar@c-cs.com wrote in news:1111097444.539000.295690
@l41g2000cwc.googlegroups.com:

> O' Please,

O', duh! Like ...

Sinan.


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

Date: Thu, 17 Mar 2005 23:45:05 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Weird HTTP heders in Html Body
Message-Id: <39ufrvF64pt7mU1@individual.net>

c_klar@c-cs.com wrote:
> When running the following script on certain web browsers in displays
> HTTP headers in the body of the page.
> 
> TestPerl.pl:
> - - - - - -
> print("HTTP/1.0 200 OK\n");
> print("Content-type: text/html\n\n");
> 
> print "a" x 2000;

What you seem to be trying to do is running a non-parsed header CGI 
script. Have you tried renaming it to nph-TestPerl.pl?

If that's not your intention, i.e. if you just want to run a usual 
("parsed") script, drop the first print() statement.

Note that your problem is about CGI, not Perl, so it's off-topic here. I 
would recommend that you study a beginners tutorial about CGI scripts in 
Perl.

http://cgi.resourceindex.com/Documentation/CGI_Tutorials/

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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


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