[29868] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1111 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 13 11:09:43 2007

Date: Thu, 13 Dec 2007 08:09:10 -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, 13 Dec 2007     Volume: 11 Number: 1111

Today's topics:
    Re: (1)[0] ok but not 1[0] <bik.mido@tiscalinet.it>
    Re: (1)[0] ok but not 1[0] <bik.mido@tiscalinet.it>
    Re: (1)[0] ok but not 1[0] <bik.mido@tiscalinet.it>
    Re: (1)[0] ok but not 1[0] <cwilbur@chromatico.net>
    Re: (1)[0] ok but not 1[0] <uri@stemsystems.com>
    Re: FAQ 4.58 How can I know how many entries are in a h <xueweizhong@gmail.com>
    Re: FAQ 4.58 How can I know how many entries are in a h <joost@zeekat.nl>
    Re: FAQ 4.58 How can I know how many entries are in a h <xueweizhong@gmail.com>
    Re: FAQ 4.58 How can I know how many entries are in a h <ben@morrow.me.uk>
    Re: FAQ 4.58 How can I know how many entries are in a h <brian.d.foy@gmail.com>
    Re: FAQ 4.58 How can I know how many entries are in a h <joost@zeekat.nl>
    Re: FAQ 4.58 How can I know how many entries are in a h <uri@stemsystems.com>
        Need help integrating a perl command into a shell scrip <rosede12@gmail.com>
    Re: Need help integrating a perl command into a shell s <RedGrittyBrick@SpamWeary.foo>
    Re: Need help integrating a perl command into a shell s <ben@morrow.me.uk>
    Re: Next Page gets downloaded in Perl <mritty@gmail.com>
        not sure why I am getting the following warning "Useles <mcardeiro@yahoo.com>
    Re: Regular expression for matching words containing un <sensorflo@gmail.com>
    Re: Regular expression for matching words containing un <RedGrittyBrick@SpamWeary.foo>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 13 Dec 2007 13:59:46 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <kha2m3dltbl9mdeickpt6h6eoe61bme6ti@4ax.com>

On Wed, 12 Dec 2007 22:37:51 +0000, Ben Morrow <ben@morrow.me.uk>
wrote:

>> Anyway, while the OP is confused by the fact e.g. 3[0] doesn't do what
>> he thinks it should, the current syntax for the wanted semantics seems
>> intuitive and dwimmy to me. I, for one, would find 3[0] to be
>> syntactically valid and semantically valid, to imply that 3 is an
>> autoboxed object (which in Perl 5 generally isn't unless using the
>> autobox module) and doing the role of an array.
>
>This isn't possible within the syntax and semantics of Perl 5, as you'd
>lose the distinction between $ary[0] and @ary[0], which is vital to get
>the proper RHS context in assignments.

In fact I said so too, later on. You also quoted that bit: "but then
it would be very inconsistent with $n[0] being the first element of
@n. If sigils were invariant as they are in Perl 6 [...]"

>> Perhaps this would have some sense if the semantics were that
>> [0..2](0),
>
>Huh? Perl never uses () for subscripting... did you mean (0..2)[0] ?

Yes, of course. It was a... speecho(?) much like "Man, this is crazy.
I hope I didn't brain my damage."

>Still doesn't make a lot of sense...

Indeed: "but there wouldn't be much need to give
3[0] a meaning, either."

>IIUC 3[0] is valid Perl 6, and means 3.[0], which may or may not make
>sense depending on what object '3' evaluates to... but it's possible I'm
>wrong, as I haven't tried using Perl 6 in anger yet.

I think so too and under pugs

  pugs> say 3[0];
  3

But that of course is not a *proof*.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 13 Dec 2007 14:09:51 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <fkb2m39giqaelbuqbm6ervaol8hsveb6nk@4ax.com>

On Thu, 13 Dec 2007 01:33:30 +0000 (UTC), Ilya Zakharevich
<nospam-abuse@ilyaz.org> wrote:

>> - I learn Perl pretty well
>> - I learn LaTeX a bit (i decided to write the document in latex)
>
>IMO LaTeX is the most unsuitable tool for source code of the docs.  As
>the minimum, it should be convertable to 1 man doc (for easy
>grepping), and/or 1-doc or multi-doc HTML.

While I'm a big LaTeX aficionado and listings.sty does an excellent
job at typesetting code, I wholeheartedly second that. Anyway, if one
does not deviate too much from standard classes and packages, TeX4HT
should do a good job for HTML conversion. I don't know if/how it works
with listings, though.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 13 Dec 2007 14:12:24 +0100
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <opb2m3lvm8d2skpgj5o77v8b010a7se4rv@4ax.com>

On Wed, 12 Dec 2007 23:53:48 -0800 (PST), Florian Kaufmann
<sensorflo@gmail.com> wrote:

>> This is an application of "parenthesis around a function's argument
>> list are optional" rule.
>
>Are you very sure? I think its an application of the more general rule

Yes, he is.

>"you can always add parentheses around an expression"

Nope.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: 13 Dec 2007 10:38:04 -0500
From: Charlton Wilbur <cwilbur@chromatico.net>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <87hcim61wj.fsf@mithril.chromatico.net>

>>>>> "FK" == Florian Kaufmann <sensorflo@gmail.com> writes:

    FK> I am writing a documentation for Perl for myself.  [...]  I am
    FK> writing it to learn Perl, to order my thoughts, my
    FK> understanding of Perl. 

Given your miscomprehensions in this thread (I've seen at least two),
and your acknowledgement that you're still learning Perl, I would like
to strongly recommend that before you make such documentation
available to the general public, you pass it around to several
experienced and knowledgeable Perl programmers for peer review
*before* you make it public.

Good intentions are a grand thing, but there are already far too many
Perl tutorials and references out there, including some that have been
printed and for which people are expected to pay money, which are full
of errors.  *Please* don't add to them.

Charlton


-- 
Charlton Wilbur
cwilbur@chromatico.net


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

Date: Thu, 13 Dec 2007 15:41:34 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: (1)[0] ok but not 1[0]
Message-Id: <x763z2lhzl.fsf@mail.sysarch.com>

>>>>> "FK" == Florian Kaufmann <sensorflo@gmail.com> writes:

  >> What are your plans for this documentation? I'm sure people are
  >> interested.

  FK> I think I'll be writing for some weeks, maybe even months. I also have
  FK> a job during the day :-). And since I am learning Perl, learning
  FK> LaTeX, fiddling at my syntax notation the progress is not fast. But of
  FK> course I'll put it under GFDL or something similar and put it on the
  FK> net. Provided I am allowed to - the basics of my work are mainly
  FK> "Programming Perl" and http://perldoc.perl.org/. I sometimes copied
  FK> whole sentences. I fear I would break their copyright when I put my
  FK> document under GFDL.

i applaud your attempt at this doc but i will wager it won't be nearly
as useful as you expect. there are dozens of perl tutorials on the net
and almost all are total crap and full of mistakes and bad writing. in
many cases the authors also were self taught and thought they can create
a better doc. turns out that writing technical docs (especially
tutorials) needs much more programming skill and tons of experience
which most of those authors don't have (or ever will have). some even
proclaim how smart they are and still fail badly. i have read many and
have posted shredding reviews on usenet in the past so go google for
some of them. consider that larry wall wrote 'programming perl' and is
considered a very good writer and of course knows perl very well. yet
some have problems with that book (note: it is NOT a tutorial or
beginner book). i will repeat it, tech writing is VERY hard and much
harder than anyone who hasn't done it realizes. it is by far harder than
programming as you have to write much more text than code, understand
the material far better than you need for coding and english (or any
other natural language) is full of ambiguity and nuance that is not
found in programming languages.

report back in 6 months for a proper review/shredding and you will find
all your time and effort will likely have been wasted. just watching how
you think in this thread tells me you are not qualified enough to write
another perl tutorial that will make any mark at all. nothing personal
but this comes from my experience reading amateur tech writing about
perl. i have also been a technical editor of 4 perl books as well as a
perl trainer and article author so i also have direct experience in this
area.

good luck, for you will need it. you don't realize how hard a task lies
ahead of you.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 13 Dec 2007 05:01:22 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <9c2af0c5-0974-404b-a0b4-02966ad157cd@i12g2000prf.googlegroups.com>



>         $num_keys = keys %hash;

Seems there is a better way to do it:

    #! /bin/perl -l

    %hash = (a=>1, b=>2, c=>3, d=>4, e);
    $num_keys = %hash+0;
    print $num_keys;

    __END__

    5

So it means when in numeric(not string) context, %hash return numbers
of keys accidently. But anyway, it's a good feature.

-Todd


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

Date: 13 Dec 2007 13:18:16 GMT
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <47613118$0$16792$e4fe514c@dreader27.news.xs4all.nl>

On Thu, 13 Dec 2007 05:01:22 -0800, Todd wrote:

>>         $num_keys = keys %hash;
> 
> Seems there is a better way to do it:
> 
>     #! /bin/perl -l
> 
>     %hash = (a=>1, b=>2, c=>3, d=>4, e);
>     $num_keys = %hash+0;

I fail to see how this qualifies as "better".

  [..]

> So it means when in numeric(not string) context, %hash return numbers of
> keys accidently. But anyway, it's a good feature.

This is indeed accidental, and as far as I know not guaranteed to work in 
any future version of perl. It's also unlikely to work with tied hashes.

Joost.






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

Date: Thu, 13 Dec 2007 06:30:13 -0800 (PST)
From: Todd <xueweizhong@gmail.com>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <54275282-2001-4be4-a5db-f1d44f48bd91@e6g2000prf.googlegroups.com>



Joost Diepenmaat wrote:
> This is indeed accidental, and as far as I know not guaranteed to work in
> any future version of perl. It's also unlikely to work with tied hashes.

But 0+%hash don't have side affect -- don't reset iterator:

    #! /bin/perl -l

    %hash = (a=>1, b=>2);

    $, = q/,/;
    print each %hash;
    $num_keys = %hash+0;
    print $num_keys;
    print each %hash;


    __END__

    a,1
    2
    b,2


    #! /bin/perl -l

    %hash = (a=>1, b=>2);

    $, = q/,/;
    print each %hash;
    $num_keys = keys %hash;
    print $num_keys;
    print each %hash;


    __END__

    a,1
    2
    a,1


Also i do some Benchmark about them, the `keys %hash' seems faster
than `0+%hash', so it means keys %hash is heavily used so that it has
been optimized.

-Todd


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

Date: Thu, 13 Dec 2007 14:54:45 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <lmt735-k5i2.ln1@osiris.mauzo.dyndns.org>


Quoth Todd <xueweizhong@gmail.com>:
> 
> Joost Diepenmaat wrote:
> > This is indeed accidental, and as far as I know not guaranteed to work in
> > any future version of perl. It's also unlikely to work with tied hashes.
> 
> But 0+%hash don't have side affect -- don't reset iterator:

You can't add to the hash while you're iterating anyway. You can delete
from it, despite what the faq says (see
http://blog.plover.com/prog/perl/undefined.html#3), but in the rare case
where you need to know the size of the hash during an modifying
iteration you can just keep a counter yourself.

More importantly, 0+%h gives a warning about a non-numeric value.

> Also i do some Benchmark about them, the `keys %hash' seems faster
> than `0+%hash', so it means keys %hash is heavily used so that it has
> been optimized.

It doesn't need to be: it's inherently a simpler operation. 0+%h has to

    - find the size of the hash
    - find the number of buckets
    - interpolate those into a string
    - convert that string back to a number
    - add 0

the latter two being separate Perl ops, which are always slow. scalar
keys %h just does the first directly.

Ben



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

Date: Thu, 13 Dec 2007 08:48:35 -0600
From: brian d  foy <brian.d.foy@gmail.com>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <131220070848356305%brian.d.foy@gmail.com>

In article
<9c2af0c5-0974-404b-a0b4-02966ad157cd@i12g2000prf.googlegroups.com>,
Todd <xueweizhong@gmail.com> wrote:

> >         $num_keys = keys %hash;
> 
> Seems there is a better way to do it:
> 
>     #! /bin/perl -l
> 
>     %hash = (a=>1, b=>2, c=>3, d=>4, e);
>     $num_keys = %hash+0;

This only works by accident. The %hash in scalar context returns the
hash statistics, which looks like a fraction ( e.g. 4/7). When you
convert that to a number by using it in the addition, you get the first
digits and Perl ignores the rest of the string. In this case, that
first numer also happened to be the number of keys, but it may not
always be that. 

You're relying on undefined behaviour instead of the documented way to
do it.


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

Date: 13 Dec 2007 15:06:22 GMT
From: Joost Diepenmaat <joost@zeekat.nl>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <47614a6e$0$16792$e4fe514c@dreader27.news.xs4all.nl>

On Thu, 13 Dec 2007 06:30:13 -0800, Todd wrote:

> Joost Diepenmaat wrote:
>> This is indeed accidental, and as far as I know not guaranteed to work
>> in any future version of perl. It's also unlikely to work with tied
>> hashes.
> 
> But 0+%hash don't have side affect -- don't reset iterator:

But the only thing you can reliably to do a hash during an iteration is 
delete the current entry. There's no need to check the size of the hash 
during a loop.

> Also i do some Benchmark about them, the `keys %hash' seems faster than
> `0+%hash', so it means keys %hash is heavily used so that it has been
> optimized.

I would expect that it's because 0+%hash first constructs a string from 
two integers and then converts that string to a number, while scalar keys 
returns the number directly.

Joost.




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

Date: Thu, 13 Dec 2007 15:45:49 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: FAQ 4.58 How can I know how many entries are in a hash?
Message-Id: <x7wsrik382.fsf@mail.sysarch.com>

>>>>> "T" == Todd  <xueweizhong@gmail.com> writes:

  >> $num_keys = keys %hash;

  T> Seems there is a better way to do it:

  T>     #! /bin/perl -l

  T>     %hash = (a=>1, b=>2, c=>3, d=>4, e);
  T>     $num_keys = %hash+0;
  T>     print $num_keys;

  T>     __END__

  T>     5

try turning on warnings.

perl -we '%h = (a =>3) ; print %h + 0'
Argument "1/8" isn't numeric in addition (+) at -e line 1.


  T> So it means when in numeric(not string) context, %hash return numbers
  T> of keys accidently. But anyway, it's a good feature.

no, it is not a feature nor is it good. please don't think you will
discover such a neat thing given how little perl you know. what a hash
returns in scalar context is documented and it is the a string with the
number of entries/the number of buckets. it will numerify to the same
value as scalar keys but it is not warning safe. this is typical newbie
mistake of not studying the docs and not enabling warnings.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 13 Dec 2007 06:15:19 -0800 (PST)
From: Daryl Rose <rosede12@gmail.com>
Subject: Need help integrating a perl command into a shell script.
Message-Id: <5ed0651e-cff1-4b5d-a140-ec3527acc98c@b40g2000prf.googlegroups.com>

I need to edit 100 or more shell scripts.  These shell scripts have
been moved, and they have a single line in them that define a specific
path.  i.e. FILEDIR="/opt/<subdir>/file"

This path needs to be changed.  The opt directory is the only
consistent within this path.  The name of the subdir, and the file
name change.

I do almost all of my work in shell, I rarely ever use PERL, but I
feel perl would be the best solution for this purpose.  I know that I
can use the substitute operator to change this line without a bunch of
messy redirects and move commands to rename the files.

The way that I was planning on doing this was something like:

find . -exec grep -l <string here> {} ;/ |while read line
do

var1=`echo $line |awk -F"/" '{print $3}'` # get the subdir name.
var2=`echo $line |awk -F"/" '{print $4}'` # get the file name.

perl -ip -e 's/SEARCH/REPLACE/' $var1/$var2

done


The problem that I am having is the SEARCH and REPLACE strings.  Since
the subdir and file name are going to change within each file, I'm not
sure how to pass the variables into the substitute command.  Could one
of you perl experts give me a suggestion on how to do this?

Thank you.

Daryl Rose



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

Date: Thu, 13 Dec 2007 15:14:56 +0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Need help integrating a perl command into a shell script.
Message-Id: <47614c70$0$8412$db0fefd9@news.zen.co.uk>

Daryl Rose wrote:
> I need to edit 100 or more shell scripts.  These shell scripts have
> been moved, and they have a single line in them that define a specific
> path.  i.e. FILEDIR="/opt/<subdir>/file"
> 
> This path needs to be changed.  The opt directory is the only
> consistent within this path.  The name of the subdir, and the file
> name change.
> 
> I do almost all of my work in shell, I rarely ever use PERL, but I
> feel perl would be the best solution for this purpose.  I know that I
> can use the substitute operator to change this line without a bunch of
> messy redirects and move commands to rename the files.
> 
> The way that I was planning on doing this was something like:
> 
> find . -exec grep -l <string here> {} ;/ |while read line
> do
> 
> var1=`echo $line |awk -F"/" '{print $3}'` # get the subdir name.
> var2=`echo $line |awk -F"/" '{print $4}'` # get the file name.
> 
> perl -ip -e 's/SEARCH/REPLACE/' $var1/$var2
> 
> done

You should be able to arrange for the shell to interpolate $var1 and 
$var2 into the perl program:

perl -i -p -e "s(/opt/\w+/\w+)(/opt/$var1/$var2)" $var1/$var2

(note the use of double quotes)

However the overall task may be more easily accomplished using Perl's 
FileFind module.

> 
> 
> The problem that I am having is the SEARCH and REPLACE strings.  Since
> the subdir and file name are going to change within each file, I'm not
> sure how to pass the variables into the substitute command.  Could one
> of you perl experts give me a suggestion on how to do this?
> 


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

Date: Thu, 13 Dec 2007 15:16:31 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Need help integrating a perl command into a shell script.
Message-Id: <fvu735-jpj2.ln1@osiris.mauzo.dyndns.org>


Quoth Daryl Rose <rosede12@gmail.com>:
> I need to edit 100 or more shell scripts.  These shell scripts have
> been moved, and they have a single line in them that define a specific
> path.  i.e. FILEDIR="/opt/<subdir>/file"
> 
> This path needs to be changed.  The opt directory is the only
> consistent within this path.  The name of the subdir, and the file
> name change.

You haven't said what you want to change it to. I'm assuming you want to
change it to FILEDIR="/new/<subdir>/file", if this isn't the case edit
appriately below.

> I do almost all of my work in shell, I rarely ever use PERL,

Perl, or perl: it's not a acronym. Some people here get quite upset when
people get it wrong. :)

> but I
> feel perl would be the best solution for this purpose.  I know that I
> can use the substitute operator to change this line without a bunch of
> messy redirects and move commands to rename the files.

FWIW you can do the same with sed (perl's -i option is inherited from
sed). I'd rather use Perl, because I hate POSIX regular expression
syntax, but using sed is more shellish.

> The way that I was planning on doing this was something like:
> 
> find . -exec grep -l <string here> {} ;/ |while read line

You need to learn about xargs. find without xargs is practically
useless. Something like

    find . | xargs grep -l <string> | xargs sed -i -Ee'...'

(-r instead of -E for GNU sed, or omit if you can stand BREs :) ).

> do
> 
> var1=`echo $line |awk -F"/" '{print $3}'` # get the subdir name.
> var2=`echo $line |awk -F"/" '{print $4}'` # get the file name.
> 
> perl -ip -e 's/SEARCH/REPLACE/' $var1/$var2
> 
> done

I would use something more like (untested)

    find . -type f | xargs perl -0377 -pi -e'/<string here>/ and 
        s,(FILEDIR)="/opt/ ([^/]+) / ([^"]+) ",$1="/new/$2/$3",gx'

(actually I'd probably do the whole thing in Perl, using
File::Find::Rule, but this is a more shellish solution). The -0377 says
to read the whole file in one go, which allows you to omit the grep
altogether while still using perl -p. The /x modifier on the s,,, allows
whitespace in the first section, which makes it at least slightly
comprehensible :).

Ben



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

Date: Thu, 13 Dec 2007 05:44:00 -0800 (PST)
From: Paul Lalli <mritty@gmail.com>
Subject: Re: Next Page gets downloaded in Perl
Message-Id: <d8ba4445-15b8-4984-8401-d6ece1bf147d@b40g2000prf.googlegroups.com>

On Dec 13, 1:19 am, Praki <visitprakashin...@gmail.com> wrote:
> Greetings All
>
> I have a Perl file in which i m doing all the operaions in one file
> based on the command line arguments.
> login.cgi
> .
> .
> .
> $query = new CGI;
> $sid = $query->cookie('CGISESSID') || $query->param('CGISESSID') ||
> undef;
> $submit_value=$query->param("submit");
>
> if ($sid ne ""){
> print $query->header( -cookie=>$cookie );}
> else{
> print "Content-type: text/html";}
>
> if ($sid eq "" && $submit_value eq "") {
>    &auth_page(" Login Authentication"," Login Authentication");
>    print "Session id: ";
>    print $sid;
>    print "\n Submit value:";
>    print $query->param("submit");
>
>    print $FORM{'uid'};
>    print $query->header( -cookie=>$cookie );
>    &print_trailer();
>  exit(0);}
>
> elsif ($sid eq "" && $submit_valu ne "") {
>         &print_header(" Login Authentication"," Login Authentication");
>         &print_trailer();
>         exit(0);}
>
> .
> .
> .
> when i open the for the first time it should go to
>
> if ($sid eq "" && $submit_value eq "")  this condition as both will be
> empty. and here i m getting the login information and again i m
> calling the same file(login.cgi). now as the sumbit value will not be
> empty it has to go the next condtion
>
> elsif ($sid eq "" && $submit_valu ne "") .i m validating the
> credentials here. but the problem here i face is the page info which
> is to be displayed in the browser is automaticaly asks for File
> Download. when downloaded that file and check by open in the new
> window it displays the ouput. i could not understand the problem so
> plz can u help me in clearing this problem...
>
> where i m going wrong..

Your content-type header is wrong.  It's missing newlines.  You're
using the $query->header() method in the if statement.  Why not in the
else statement?

if ($sid ne ""){
  print $query->header( -cookie=>$cookie );
}
else{
  print $query->header( );
}

(A completely separate problem is that you're later trying to print
the header with some cookies, after you've already printed both header
and content.  That's not going to work.  You need to rework your
logic).

Paul Lalli


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

Date: Thu, 13 Dec 2007 06:52:16 -0800 (PST)
From: "mcardeiro@yahoo.com" <mcardeiro@yahoo.com>
Subject: not sure why I am getting the following warning "Useless use of a  constant in void context"
Message-Id: <37df31b3-155b-4b23-8963-b4136b580a2c@t1g2000pra.googlegroups.com>

Hello

I have a line of code that is creating an entry in a mysql table using
DBI.  I have the record values for the insert in a hash reference.  A
separate array  holds information about the table structure so that
when I do my insert I map the hash ref using the array so only
relevant values are entered into the execute statement and they are in
the proper order.

It works exactly as it is supposed to but I keep getting a warning
from perl "Useless use of a constant in void context at /var/www/web1/
lib/TS.pm line 1258."

I am ignoring it because the code works, but figure I'll throw it out
there in case I am doing something boneheaded.

heres some code fragments:

#######################################################################################
###holds info about the structure of the table and is used to verify
data before entry
########################################################################################
our @userTableOrder	= (
			{	'name'		=> 'username',
				'required'	=> 1,
				'regexp'	=> '^[\w\d]{1,15}$',
			},

			{	'name'		=> 'password',
				'required'	=> 1,
			},
			{	'name'		=> 'authorize',
				'required'	=> 1,
				'regexp'	=> '^[\d]+$',
			},
	);

############################
### record to be inserted
##########################
my $newUser =  {
                'username'	=> 'mcardeiro',
		'password'	=> 'booba',
		'authorize'	 => 3,
		'workgroup'	=> 'philadelphia',
		};

############################
### DBI stuff
##########################
$sth	= $dbh->prepare("INSERT INTO users VALUES (?,?,?")
			|| error_page("cant prepare insert statement at userEntry: $dbh-
>errstr");

#############################################################
#####  the code below is causing the warning...why?
#########################################################
$sth->execute(	map {$newUser->{$_->{'name'}}} @userTableOrder)
			|| error_page("cant execute insert statement at userEntry: $dbh-
>errstr");


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

Date: Thu, 13 Dec 2007 00:17:45 -0800 (PST)
From: Florian Kaufmann <sensorflo@gmail.com>
Subject: Re: Regular expression for matching words containing underscore _  character
Message-Id: <54084bbc-bb7a-4dec-b278-3d623b016b0a@b1g2000pra.googlegroups.com>

On Dec 12, 4:27 pm, Raj <rsp...@gmail.com> wrote:
> I have large text passages containing names of database tables,
> procedures, packages, variables etc having the underscore character as
> a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
> Z0-9_]+\b" but it matches all words in the passage.
>
> Thanks in advance for the help.
>
> Raj

I would use this to merly find lines wich contain what you search
/\p{IsAlnum}+_)+\p{IsAlnum}+/

I would use this to get the words you search into an array
/((?:\p{IsAlnum}+_)+\p{IsAlnum}+)/g

Example:
perl -ne 'print @a if (@a = /((?:\p{IsAlnum}+_)+\p{IsAlnum}+)/g)' <<<
'yyy_yyy saf_;fasl asfd ; xxx_xxx'

Greetings

Flo


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

Date: Thu, 13 Dec 2007 10:11:02 +0000
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.foo>
Subject: Re: Regular expression for matching words containing underscore _ character
Message-Id: <47610536$0$13940$fa0fcedb@news.zen.co.uk>

Tad J McClellan wrote:
> RedGrittyBrick <RedGrittyBrick@SpamWeary.foo> wrote:
>> Raj wrote:
>>> I have large text passages containing names of database tables,
>>> procedures, packages, variables etc having the underscore character as
>>> a part of the name. eg. rsp_names_friends_master. I tried "\b[a-zA-
>>> Z0-9_]+\b" but it matches all words in the passage.
>> Similarly "[ab]+" matches "aaa" and "aa" though neither contain "b".
>>
>> Try "\b[a-zA-Z0-9]+_[a-zA-Z0-9_]+\b"
>>
>> Or "\b\w+_\w+\b"
> 
> 
> Three (six?) useless uses of word boundary in the quotes above...
> 
> Every pattern there will behave identically without any \b's.
> 
> 

TFTC

$ perl -e 'print "$_\n" for "_aa-bbb.cc_[d_d]" =~ /\w+/g'
_aa
bbb
cc_
d_d

$ perl -e 'print "$_\n" for "_aa-bbb.cc_[d_d]" =~ /\w+_\w+/g'
d_d

In Perl programs I've written, I don't think I've ever used \b. Perhaps 
I should have analyzed the OP's RE completely rather than only 
commenting on the primary reason for the problem.


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

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 V11 Issue 1111
***************************************


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