[24713] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6868 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 16 03:07:19 2004

Date: Mon, 16 Aug 2004 00:05:04 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 16 Aug 2004     Volume: 10 Number: 6868

Today's topics:
    Re: Counting text area <john.sharpe@nospambtinternet.co.uk>
    Re: Counting text area <noreply@gunnar.cc>
    Re: Getting position from unpack (was: "join on space i (Anno Siegel)
    Re: howto convert a *nix DB_File to windows? (dan baker)
    Re: howto convert a *nix DB_File to windows? <noreply@gunnar.cc>
        Problems with proxy .. (Idan Jan)
    Re: testing without shell access <gifford@umich.edu>
    Re: Untaint file name <john.sharpe@nospambtinternet.co.uk>
    Re: Untaint file name <gnari@simnet.is>
    Re: Untaint file name <john.sharpe@nospambtinternet.co.uk>
        using $1 in a regex <jeff@spamalanadingong.com>
    Re: using $1 in a regex <noreply@gunnar.cc>
    Re: using $1 in a regex <sholden@flexal.cs.usyd.edu.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sun, 15 Aug 2004 18:27:57 +0000 (UTC)
From: John S <john.sharpe@nospambtinternet.co.uk>
Subject: Re: Counting text area
Message-Id: <Xns9546C61111EBAjohnsharpenospambtin@217.32.252.50>

Tore Aursand <tore@aursand.no> wrote in news:pan.2004.08.13.08.48.02.412737
@aursand.no:

> On Fri, 13 Aug 2004 10:26:56 +0200, Davidd Sargent wrote:
>> What I want is on the results page for it to count the number of
>> subdomains (each domain will be seperated by \n (a newline)).
> 
> 1. Read the FORM data by using CGI.pm.
> 2. Get the lines by splitting on "\n"
> 3. Process each line, discard those which doesn't meet your "subdomain
>    requirements".
> 4. Present the result for the user.
> 
> 

textarea comes back with \r as well.


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

Date: Sun, 15 Aug 2004 21:32:06 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Counting text area
Message-Id: <2o9scnF8db61U1@uni-berlin.de>

John S wrote:
> Tore Aursand wrote:
>> On Fri, 13 Aug 2004 10:26:56 +0200, Davidd Sargent wrote:
>>
>>> What I want is on the results page for it to count the number of
>>> subdomains (each domain will be seperated by \n (a newline)).
>>
>> 1. Read the FORM data by using CGI.pm.
>> 2. Get the lines by splitting on "\n"
>> 3. Process each line, discard those which doesn't meet your "subdomain
>>    requirements".
>> 4. Present the result for the user.
> 
> textarea comes back with \r as well.

Only on Windows (of course), and not if you use a library that takes 
care of it, such as CGI.pm (as Tore suggested) or cgi-lib.pl. 
Otherwise you can binmode STDOUT to prevent the \r pecularity.

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


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

Date: 15 Aug 2004 14:39:19 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Getting position from unpack (was: "join on space instead of comma")
Message-Id: <cfnsin$87c$1@mamenchi.zrz.TU-Berlin.DE>

J. Romano <jl_post@hotmail.com> wrote in comp.lang.perl.misc:
> Tassilo v. Parseval wrote:
> 
> > here's one that I find useful, namely the '/' construct.
> > The template preceeding the slash is used as a count
> > argument for the template following the slash:
> 
> <code snipped>
> 
> > Note how this can be combined with @:
> >
> >     my @x = unpack '@2c/C', "\x03\x00\x01\xff\x03";
> >     print "@x\n",
> >     __END__
> >     255
> 
>    Before that thread, I wasn't aware that I could use '@' like that
> to start the position of unpacking.  Before I learned about '@', I
> would always use substr() to remove the beginning part of the string
> that I wanted to ignore.
> 
>    But that brings me to another question, one that concerns the usage
> of the '/' construct.  I've used that construct before, but I could
> never find an easy way to figure out my offset into the string after
> I've used it.
> 
>    Let me clarify with an example.  Say I have the following piece of
> code:
> 
>       my $string = "\x00\x01\x03\x00\x01\xff\x01\x0f";
>       # or I could say:  my $sring = v0.1.3.0.1.255.1.15;
>       my @x = unpack '@2 c/C', $string;
> 
> That would make @x have three elements:  0, 1, and 255.
> 
>    Now let's say that, after examining the contents of @x, I decide to
> read in data for @y, starting where @x left off:
> 
>       my @y = unpack '@6 c/C', $string;
> 
> That would make @y have only one element:  15.
> 
>    However, in order to know that the second unpack command must start
> at offset 6, I would have to calculate how many elements are in @x,

[snip discussion]

That's hard to do, though I think there's a module that calculates the
length of the storage image of pack/unpack templates.

In this case it isn't even necessary.  Just make a copy of the rest of the
string using an additional "a*" template.

    my $string = "\x00\x01\x03\x00\x01\xff\x01\x0f";
    my @x = unpack '@2 c/C a*', $string;
    $string = pop @x;

Now $string contains whatever wasn't consumed by the template before
"a*".  So

    my @y = unpack 'c/C', $string;

gives the right result without explicitly calculating an offset.

Anno


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

Date: 15 Aug 2004 16:30:45 -0700
From: botfood@yahoo.com (dan baker)
Subject: Re: howto convert a *nix DB_File to windows?
Message-Id: <13685ef8.0408151530.c3d1005@posting.google.com>

Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message news:<2o6spoF7gnc6U1@uni-berlin.de>...
> dan baker wrote:
> > Paul Marquess wrote:
> >> If DB_File has been built with the same version of Berkeley DB on
> >> your Unix box and your Windows box, the data files can be read on
> >> either.
> > 
> > Its a different version. I use the pre-compiled stuff from
> > activestate on windows, and the remote webserver has a little bit
> > newer libs installed. I move the files in binary mode, but they
> > dont seem to be compatible.
> 
> In your original post you were talking about a "little application".
> If the hash is small as well, why not switch from DB_File to the
> simple but compatible SDBM_File?
------------

I cant remember the limitations fo the SDBM versus the DB... I think
at the time I had some reason for using DB_File. The largest of the
files is maybe 10k-20k records, with about 20 "fields" of information
of variable length. Basically I store them as key, string with special
character delimiters, and pack/unpack fromt he string to fields when I
need them.


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

Date: Mon, 16 Aug 2004 01:43:23 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: howto convert a *nix DB_File to windows?
Message-Id: <2oab4hF8ce3hU1@uni-berlin.de>

dan baker wrote:
> Gunnar Hjalmarsson wrote:
>> If the hash is small as well, why not switch from DB_File to the 
>> simple but compatible SDBM_File?
> 
> I cant remember the limitations fo the SDBM versus the DB... I
> think at the time I had some reason for using DB_File. The largest
> of the files is maybe 10k-20k records, with about 20 "fields" of
> information of variable length.

Okay... An SDBM_File key/value pair may not exceed ~ 1,000 bytes, so
if you have records of 10-20k size, SDBM_File is not an option.

I just tried to be creative. :)

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


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

Date: 15 Aug 2004 12:50:00 -0700
From: idan.jan@gmail.com (Idan Jan)
Subject: Problems with proxy ..
Message-Id: <2ca34262.0408151150.168bfb2d@posting.google.com>

Hi all, 
Hope you could help me with this problem.
I have the following code (please forgive the ugliness) :

== code start == 	
$url = 'http://www.alexa.com/data/details/traffic_details?q=&url=cnn.com';
	
$ua = LWP::UserAgent->new;
$ua->proxy(http => $proxyserver);
$req = HTTP::Request->new(GET => $url);
$file = $ua->request($req)->as_string;
		
print "$file\n";
== code end == 

I get the following output:
=== output start === 
HTTP/1.0 202 Accepted
Date: Sun, 15 Aug 2004 19:20:54 GMT
Server:
Content-Length: 0
Content-Type: text/text
Client-Date: Sun, 15 Aug 2004 20:23:44 GMT
Client-Peer: 80.121.233.206:8000
Client-Response-Num: 1
Proxy-Connection: close
X-Cache: MISS from oxo.demo.com
=== output end === 

As you can see, I don't get the actual http data from the site, only
the above output. With other $urls this code works perfectly, but with
this alexa url, I only get the above output.

As far as I know, the HTTP 202 code isn't an Error code, so I really
can't tell what's the problem... ?


Would appriciate any help !

Idan


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

Date: 16 Aug 2004 00:08:11 -0400
From: Scott W Gifford <gifford@umich.edu>
Subject: Re: testing without shell access
Message-Id: <qszk6vzn2s4.fsf@mspacman.gpcc.itd.umich.edu>

"Dan" <news.groups@earthlink.net> writes:

[...]

> The probelm is that the hosting service provides no shell access, so I have
> no way to test and debug the Perl scripts once I've uploaded them to the
> hosting service.

I frequently use a small shell script in this situation, which does
something like:

    #!/bin/sh -x
    
    printf "Content-type: text/plain\n\n"
    exec 2>&1
    exec ./myscript.cgi

I would name this script something like "myscript.debug", and if the
script isn't running right or won't compile, I would point my browser
to myscript.debug instead of myscript.cgi to see what errors and
warnings Perl is printing.  Sometimes I'll throw an "env" in there so
I can see what environment variables Apache is setting.

If you can find where the error log is, you could also write a small
script that displays the last 50-100 lines of the error log, which you
could look at to see what errors your script was producing.

-----ScottG.


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

Date: Sun, 15 Aug 2004 13:43:00 +0000 (UTC)
From: John S <john.sharpe@nospambtinternet.co.uk>
Subject: Re: Untaint file name
Message-Id: <Xns954695C07B34Ajohnsharpenospambtin@217.32.252.50>

Many thanks for prompt replies. You have answered my concerns.

My 'email this article to a friend' cgi script receives the email address 
and path from a form. It opens the file, tokeparsers it and emails it.

One more question:
The script is in a directory 2 levels down from the root. To open the file 
I am adding '../../' to the front of the string. Is this a concern?

Thanks again
wfsp

(I always have a massive attack of FUD in general and with taint in 
particular!)



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

Date: Sun, 15 Aug 2004 14:59:16 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Untaint file name
Message-Id: <cfntk6$9gg$1@news.simnet.is>

"John S" <john.sharpe@nospambtinternet.co.uk> wrote in message
news:Xns954695C07B34Ajohnsharpenospambtin@217.32.252.50...
> Many thanks for prompt replies. You have answered my concerns.
>
> My 'email this article to a friend' cgi script receives the email address
> and path from a form. It opens the file, tokeparsers it and emails it.
>
> One more question:
> The script is in a directory 2 levels down from the root. To open the file
> I am adding '../../' to the front of the string. Is this a concern?

you mean, if the user sends filename 'etc/passwd', you will send
'/etc/passwd' to him by email ? or did you mean document root?

it is better to use an absolute path to your articles, and make sure the
input
filename does not contain ../ , so if the filename is foo/bar, you add
'/my/arcticles/' to get '/my articles/foo/bar'.
this would give access to all files under /my/articles/
if you only want to give access to a subset of the files, you either
need to find a pattern that matches only those files, or look up
the filename in a hash or something.

gnari






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

Date: Sun, 15 Aug 2004 16:20:54 +0000 (UTC)
From: John S <john.sharpe@nospambtinternet.co.uk>
Subject: Re: Untaint file name
Message-Id: <Xns9546B0862B710johnsharpenospambtin@217.32.252.50>

"gnari" <gnari@simnet.is> wrote in news:cfntk6$9gg$1@news.simnet.is:

> "John S" <john.sharpe@nospambtinternet.co.uk> wrote in message
> news:Xns954695C07B34Ajohnsharpenospambtin@217.32.252.50...
>> Many thanks for prompt replies. You have answered my concerns.
>>
>> My 'email this article to a friend' cgi script receives the email
>> address and path from a form. It opens the file, tokeparsers it and
>> emails it. 
>>
>> One more question:
>> The script is in a directory 2 levels down from the root. To open the
>> file I am adding '../../' to the front of the string. Is this a
>> concern? 
> 
> you mean, if the user sends filename 'etc/passwd', you will send
> '/etc/passwd' to him by email ? or did you mean document root?
> 
> it is better to use an absolute path to your articles, and make sure
> the input
> filename does not contain ../ , so if the filename is foo/bar, you add
> '/my/arcticles/' to get '/my articles/foo/bar'.
> this would give access to all files under /my/articles/
> if you only want to give access to a subset of the files, you either
> need to find a pattern that matches only those files, or look up
> the filename in a hash or something.
> 
> gnari
> 
Sorry, yes, I meant document root. You're right, the absolute path would 
be better and I can find a pattern for the subset.

Many thanks,
wfsp



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

Date: Sun, 15 Aug 2004 20:00:12 GMT
From: Jeff Thies <jeff@spamalanadingong.com>
Subject: using $1 in a regex
Message-Id: <ghPTc.22974$nx2.11036@newsread2.news.atl.earthlink.net>

I'd like to remember a match and use it later in the regex.

Something like this:

$test=~s/foo(.*?) (.*?) $1/$2/g;

but working, of course!

so that it would match:

foobar something bar

or

foome something else me

Jeff


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

Date: Sun, 15 Aug 2004 22:43:05 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: using $1 in a regex
Message-Id: <2oa0i2F85rljU1@uni-berlin.de>

Jeff Thies wrote:
> I'd like to remember a match and use it later in the regex.
> 
> Something like this:
> 
> $test=~s/foo(.*?) (.*?) $1/$2/g;
> 
> but working, of course!
> 
> so that it would match:
> 
> foobar something bar
> 
> or
> 
> foome something else me

     $test =~ s/foo(.*?) (.*?) \1/$2/g;
------------------------------^

Use \{digit} instead of ${digit} variables at the left side of the 
s/// operator.

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


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

Date: 15 Aug 2004 22:10:38 GMT
From: Sam Holden <sholden@flexal.cs.usyd.edu.au>
Subject: Re: using $1 in a regex
Message-Id: <slrnchvnqu.6sn.sholden@flexal.cs.usyd.edu.au>

On Sun, 15 Aug 2004 20:00:12 GMT, Jeff Thies <jeff@spamalanadingong.com> wrote:
> I'd like to remember a match and use it later in the regex.
>
> Something like this:
>
> $test=~s/foo(.*?) (.*?) $1/$2/g;
>
> but working, of course!
>
> so that it would match:
>
> foobar something bar
>
> or
>
> foome something else me
>
> Jeff

perldoc perlre

The paragraph beginning:

        The bracketing construct "( ... )" creates capture buffers. To
        refer to the digit'th buffer use \<digit> within the match.

might be a good part to read, but the whole thing should be read before
posting a regex question here...

-- 
Sam Holden


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

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


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