[9620] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3214 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Jul 21 10:17:26 1998

Date: Tue, 21 Jul 98 07:02:03 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Tue, 21 Jul 1998     Volume: 8 Number: 3214

Today's topics:
    Re: RegExps: Check if string consists of EXACTLY 3 digi (Eric Harley)
    Re: Restricting refering domains access to script? (brian d foy)
    Re: Restricting refering domains access to script? (brian d foy)
    Re: Silly things to do in Perl (or: is that Laptop wate (Steve Linberg)
    Re: SMB and Timestamps (Larry Rosler)
    Re: Sticking in NULL after split(II) merzky@physik.hu-berlin.de
    Re: Sticking in NULL after split (Douglas Wilson)
        use strict <gil_brown@hp.com>
    Re: use strict <joneil@cks.ssd.k12.wa.us>
    Re: w3c/CERN directory protection (brian d foy)
    Re: What is awk better at than perl? (Larry quote) <kperrier@blkbox.com>
    Re: What's wrong? (hymie!)
        wordwrap code snippet <tyoud@u.washington.edu>
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Wed, 15 Jul 1998 10:30:20 -0700
From: eharley@pacbell.net (Eric Harley)
Subject: Re: RegExps: Check if string consists of EXACTLY 3 digits ??
Message-Id: <eharley-1507981030210001@seletar.ap.deuba.com>

> I am writing a CGI script which accepts input via QUERY_STRING. 
> However, the input is only valid if it consists of EXACTLY 3 DIGITS!  No
> more , no less, no other characters in front, after or in between the
> digits.  Ive tried things such as:
> 
> if ($ENV{'QUERY_STRING'} =~ /[0-9]\{3\}/)
> {
>   print "String is valid";
> }
> else
> {
>   print "Invalid input";
> }

The winded path would be

if ( (length $q == 3) and ($q =~ /[0-9][0-9][0-9]/) ) {
   print "Valid\n";
} else {
   print "Invalid\n";
}

but this would suffice
if ($q =~ /^[0-9]{3}$/) {
   print "Valid\n";
} else {
   print "Invalid\n";
}

-- 
Eric Harley
Freelance Programmer
  You need it done, I'm your man.

eharley@pacbell.net
http://burn.victim.com/~eharley


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

Date: Thu, 16 Jul 1998 14:00:44 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Restricting refering domains access to script?
Message-Id: <comdog-ya02408000R1607981400440001@seletar.ap.deuba.com>
Keywords: from just another new york perl hacker

In article <6ol1eo$8bc$1@news.iastate.edu>, kortbein@iastate.edu (Josh Kortbein) posted:

>Abigail (abigail@fnx.com) wrote:
>: brian d foy (comdog@computerdog.com) wrote on MDCCLXXX September MCMXCIII
>: in <URL: news:comdog-ya02408000R1607980002520001@news.panix.com>:
>: ++ In article <6ojf30$s6$1@camel15.mindspring.com>, "Doug Younger" <cgi-bin@mindspring.com> posted:
>: ++ 
>: ++ >Hello,
>: ++ >$ENV{REMOTE_HOST} is the machine where the end user is sitting at... (or
>: ++ >$ENV{REMOTE_ADDR} for IP address.
>: ++ > If you want where the script was called from (from a web page not on the
>: ++ >same server), which I doubt is the case, but just in case, use:
>: ++ >$ENV{HTTP_REFERER} will need to split out the server portion as it contains
>: ++ >the entire URL.
>: ++ 
>: ++ of course, none of those are reliable due to proxies and broken 
>: ++ browsers.
>
>: Broken? Broken? First of all, a browser isn't sending the IP number
>: (or name) - that can be interfered from the TCP/IP connection.
>
>: As for REFERER, the RFC does not make it a requirement, and
>: in certain cases, browser should not even send a REFERER header.

perhaps 'proxies and browsers' should have been 'proxies or
browsers'.  i never meant for anyone to infer that the browser
was able to tell the server anything about the TCP connection - just
the extra request header stuff.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


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

Date: Thu, 16 Jul 1998 13:58:40 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: Restricting refering domains access to script?
Message-Id: <comdog-ya02408000R1607981358400001@seletar.ap.deuba.com>
Keywords: from just another new york perl hacker

In article <linberg-1607981300330001@projdirc.literacy.upenn.edu>, linberg@literacy.upenn.edu (Steve Linberg) posted:

>In article <6ol1eo$8bc$1@news.iastate.edu>, kortbein@iastate.edu (Josh
>Kortbein) wrote:
>
>> Abigail (abigail@fnx.com) wrote:
>> 
>> : Ob Puzzle: Name 3 cases where there is no sensible REFERER to send
>> :            for a browser.
>> 
>> Offhand, two of them seem to be
>> 
>> 1) when the default home page is loaded
>> 2) when a URL is typed into the "Location" widget
>
>3) When a bookmark is used
>4) When a URL is passed as a parameter to a browser

5) when certain browsers do not clear their REFERER memory after
a change of context.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


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

Date: Wed, 15 Jul 1998 14:16:55 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: Silly things to do in Perl (or: is that Laptop waterproof?)
Message-Id: <linberg-1507981416550001@seletar.ap.deuba.com>

In article <35A5F598.985CCD6B@nortel.co.uk>, "F.Quednau"
<quednauf@nortel.co.uk> wrote:

> Oh *shish*, you're all a bunch of perfectionists :)

That's *sheesh*, not *shish*.  :)

PS:  :)

PPS:  :)  :)  :)
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: Wed, 15 Jul 1998 10:13:08 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: SMB and Timestamps
Message-Id: <MPG.1016830065f5ec35989715@seletar.ap.deuba.com>

In article <6oil31$aph$1@nntp.msstate.edu> on 15 Jul 1998 16:24:01 GMT, 
Brent Johnson <brentj@ext.msstate.edu> says...
> I am trying to write a Perl script which scans through a common
> public directory and moves any files older than a certain date
> to another directory.  Problem is, when someone saves a file to
> a mounted SMB filesystem, it keeps the original file date.
> 
> Is there a way to 'touch' files when they are copied?  Or some
> other way?  I've looked at the creation times (same as it is
> on their PC's), modified times (no help there) and the 'atime' ..
> which I have no idea what that is.. but it isnt correct.
> 
> Any help would be appreciated,
> 
> - Brent

Look at `perldoc -f utime`.  The utime() function should let you do what 
you want, and is OS-independent, whereas the `touch` command is OS-
dependent.

-- 
Larry Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Wed, 15 Jul 1998 17:30:42 GMT
From: merzky@physik.hu-berlin.de
Subject: Re: Sticking in NULL after split(II)
Message-Id: <6oip02$5pl$1@seletar.ap.deuba.com>


> >A simple workaround would be:
> >(for all vars, you could use a field here...)
>
> >@vars = split (/:/);
> >foreach $var (@vars) {
> >   unless (defined ($var)) {
> >      $var = "NULL";
> >}
>
> >#... stick them togethsr:
> >$outstring = join (/,/, @vars);
>
>
> That doesn't compile (missing })

Hmm, elm does not know how to execute perl sripts on the fly...
it's a shame, i know... :-) (well, I could try a shell escape
and parse the tmp-message file for #!/...perl, execute the script
in an eval and check the error message... - No bad idea finally,
I'll think about it..;-)

> - also, see Larry's point about
> empty split()-resultant fields being nonetheless defined.

Hmm, thats right of course...
ok, for the original asker:

@vars = split (/:+/);

Is much better, since you avoid empty fields.
But number of fields can vary now...


Andre.

--
 ____________________________________________________________________
|                                 |                                  |
|  Andre Merzky                   |                                  |
|  Dep. of Physics - EEP I        |  Kathrin Kirsch & Andre Merzky   |
|  Humboldt University of Berlin  |  bij Beekma                      |
|  Invalidenstr. 49               |  van Boetzelaerstraat 5^3        |
|  D-10115 Berlin                 |  NL-1051 CS Amsterdam            |
|  Tel.: ++49 - 30 - 2093 7988    |  Tel.: ++49 - 171 - 280 24 12    |
|                                 |                                  |
|                                ---                                 |
|       pinocchio@earthling.net   -  http://home.pages.de/~pino      |
|        __o                     ---                                 |
|      _`\<,_                                                        |
|____ (_)/ (_) _________________________________think global_________|


-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: Wed, 15 Jul 1998 18:26:14 GMT
From: dgwilson@gte.net (Douglas Wilson)
Subject: Re: Sticking in NULL after split
Message-Id: <6ois82$7eq$1@seletar.ap.deuba.com>

On Wed, 15 Jul 1998 09:12:20 -0700, Nathan Franzen
<franzen@pmel.noaa.gov> wrote:

>On 15 Jul 1998, Mark-Jason Dominus wrote:
>p.s.  But how do you get an array of length 11 out of
>
>@array = split /,/, '1,2,3,,5,,,,,,,'; ?
>
>Here's how:
>
>@array = split /,/, '1,2,3,,5,,,,,,,', -1;
>pop @array;
>
>But isn't that a little clunky?  

Not really, its rather arbitrary whether or not a delimiter at
the end of the string means that the last field is NULL
(In which case you don't need the pop) or whether the last
field is before the delimiter (in which case you do need
the pop or a substitute before the split).
And the behavior of split regarding a negative limit
is documented in perldoc perlfunc.

Cheers,
Douglas Wilson


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

Date: Wed, 15 Jul 1998 13:16:12 -0400
From: "Gil Brown" <gil_brown@hp.com>
Subject: use strict
Message-Id: <6oio53$gbn$1@seletar.ap.deuba.com>

I trying to learn perl5 (I've only written stuff in 4 so far) and I am
having a problem with use strict. All I want to do is read from a file
(simple enough) and when I uncomment use strict nothing works and it does
when I comment it. This is the example I am referring to:

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

my $fh = new FileHandle; # Create local filehandle
open ($fh, "/home/gbrown/test/lolo") || die $!;
$line = <$fh>;
print "$line\n";
while ($line ne "")
{
        print "$line\n";
        $line = <$fh>;
}

Thank you for your help!

P.S. This is the error message I get when I use use strict

# ./test
Global symbol "line" requires explicit package name at ./test line 10.
Execution of ./test aborted due to compilation errors.




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

Date: Thu, 16 Jul 1998 10:56:24 -0700
From: Jerome O'Neil <joneil@cks.ssd.k12.wa.us>
To: abraham@mpi.com
Subject: Re: use strict
Message-Id: <35AE3EC8.6368BD4C@seletar.ap.deuba.com>

abraham@mpi.com wrote:
> 
> In article <6oio53$gbn$1@ocean.cup.hp.com>,
> 
> Change $line to my $line or $main::line and you'll be ok.
> 
> P.S. Why are you using strict if you don't know what it does?

With as much chest beating as goes on here about using strict and -w
(thats a Good Thing, BTW),  I'm surprized it matters.

I would interpret it as:
"I don't quite know what strict does, but everyone says it's good, so
I'll take their word for it, use it, and learn the details later."

Jerome "Strictly Speaking" O'Neil


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

Date: Tue, 14 Jul 1998 15:45:57 -0400
From: comdog@computerdog.com (brian d foy)
Subject: Re: w3c/CERN directory protection
Message-Id: <comdog-ya02408000R1407981545570001@seletar.ap.deuba.com>
Keywords: from just another new york perl hacker

In article <gLKq1.838$Xt1.3960417@newsr2.u-net.net>, "I.M.Hay" <i.m.hay@man0524.wins.icl.co.uk> posted:

>Tony Curtis wrote in message
>>It's not clear what "one at a time" actually means here.
>>Nor indeed what "user" means.  If you could elaborate...
>
>
>A user is someone using a browser to access the pages. Another user would be
>someone using another browser (probably on another PC) to access the pages.
>By one at a time I mean that once a 'user' has been authenticated only they
>can access the pages, until they stop accessing them - but, of course, you
>can't de-authenticate yourself!

you can de-authenicate yourself by forcing the browser to request
credentials again and causing the transaction to fail.

however, you may look into the various database authentication 
modes available with Apache (and mod_perl).  you could easily
change the passwords or credentials on the fly.  i tend to 
code this sort of thing myself so that i can include an expiration
time after which the user has to re-authenticate or stop using the
service.  mod_perl and DBI are invaluable for this.

-- 
brian d foy                                  <comdog@computerdog.com>
CGI Meta FAQ <URL:http://computerdog.com/CGI_MetaFAQ.html>
Comprehensive Perl Archive Network (CPAN) <URL:http://www.perl.com>
Perl Mongers Travel Deals! <URL:http://www.pm.org/travel.html>


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

Date: 21 Jul 1998 08:07:02 -0500
From: Kent Perrier <kperrier@blkbox.com>
Subject: Re: What is awk better at than perl? (Larry quote)
Message-Id: <ysir9zfz72h.fsf@blkbox.com>

Uri Guttman <uri@sysarch.com> writes:

> 
> and anyhow ilya (IIRC) has said that this feature will be in 5.005, so
> it is moot about how deep perl will go with $/ being a regex. it will go
> as deep as you tell it to.
> 

Look at Ilya's post again.  It said NOT in 5.005, but it will be in some
future release of perl.

Kent


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

Date: 21 Jul 1998 13:20:42 GMT
From: hymie@lactose.smart.net (hymie!)
Subject: Re: What's wrong?
Message-Id: <6p24ja$smg$1@news.smart.net>

In our last episode, the evil Dr. Lacto had captured our hero,
  Wilson Henriquez <henrwi00@usfca.edu>, who said:
>    I'm starting to learn perl from Learning Perl(O'reilly), and I am
>having trouble.  I'm running Linux and use joe to create a text file
>named ex.  In ex I put the following code,

Here might be your first problem -- it's a bad idea to use an existing
command name for programs you write.  Double-check to ensure that,
when you run "ex", you are running the program you wrote, rather than
the system command.

 ..hymie!         http://www.smart.net/~hymowitz         hymie@lactose.smart.net
Seems I'm not alone at being alone -
A hundred billion castaways looking for a home.                         --Sting


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

Date: Tue, 21 Jul 1998 05:36:51 -0700
From: "T. Youderian" <tyoud@u.washington.edu>
Subject: wordwrap code snippet
Message-Id: <Pine.OSF.3.96b.980721001149.373A-100000@saul1.u.washington.edu>


Hi there, I wrote a quick subroutine to take a entry from the textfield
off a web page and to quickly rework it so that it doesnt run-on in one
big long line.  Here's the function... it has a bug though :)
(It still mostly works!!)  The bug is that it seems like if you call the
function multiple times, it concatenates the output one onto the end of
another... maybe thats not really a bug, just an effect of @_ ?
Need enlightenment, hope you see the problem right off :)  I would
normally do something like this in c with strtok() but I thought I'd try
it with perl and it was surprisingly easy?


---------------------------------------------
#!/usr/local/bin/perl


#----------------------------------
# take a run-on string and put in returns
# so that it wraps nicely
#----------------------------------
sub wordwrap {
    local($entry) = pop(@_);

    $linelength = 65;

    @words = split(/[ \t\n]+/,$entry);

    $len = 0;
    foreach $word (@words) {
        if ($len + length($word) >= $linelength) {
            if ($len != 0) {
                $newentry = join('', $newentry, "\n");
            }
            $len = 0;
            $newentry = join('', $newentry, "$word ");
            $len += length($word) + 1;
        } else {
            $newentry = join('', $newentry, "$word ");
            $len += length($word) + 1;
        }
    }
    $newentry = join('', $newentry, "\n");

# Put in a space after a ". ", "! " or a "? " to make it look nice
    $newentry =~        s/\. /\.  /g;
    $newentry =~	s/\! /\!  /g;
    $newentry =~        s/\? /\?  /g;
 
    $newentry;
}

$entry = "Yeah, you know it baby!!! Supercalifragilisticexpialidocious! The quick brown fox jumps over the lazy dog. When the cat's away, the mice will play. Hey diddle diddle, the cat and the fiddle, the cow jumped over the moon. Three blind mice, three 
blind mice, see how they run, see how they run.\n";

$entry = &wordwrap($entry);

print "Entry:\n";
print $entry;





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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 3214
**************************************

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