[24056] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6253 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Mar 13 14:05:42 2004

Date: Sat, 13 Mar 2004 11:05:07 -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           Sat, 13 Mar 2004     Volume: 10 Number: 6253

Today's topics:
    Re: [OT] Re: Spreadsheet::WriteExcel - Excel 97 install <thens@NOSPAMti.com>
    Re: C expressions in Perl <tassilo.parseval@rwth-aachen.de>
    Re: C expressions in Perl <tore@aursand.no>
    Re: C expressions in Perl <tassilo.parseval@rwth-aachen.de>
        extracting the contents of the <title> tag (Martin L.)
    Re: extracting the contents of the <title> tag <jwillmore@remove.adelphia.net>
    Re: extracting the contents of the <title> tag <wherrera@lynxview.com>
        File Creation From Form <bill@hotmail.com>
    Re: File Creation From Form <noreply@gunnar.cc>
    Re: File Creation From Form <bill@hotmail.com>
    Re: File Creation From Form <noreply@gunnar.cc>
    Re: File Creation From Form <bill@hotmail.com>
    Re: File Creation From Form <noreply@gunnar.cc>
    Re: File Creation From Form <tadmc@augustmail.com>
    Re: File Creation From Form <flavell@ph.gla.ac.uk>
    Re: File Creation From Form <flavell@ph.gla.ac.uk>
    Re: File Creation From Form <noreply@gunnar.cc>
    Re: File Creation From Form <flavell@ph.gla.ac.uk>
        help with HTTP::Daemon <m.amedeo@NOSPAMatt.net>
    Re: how to reset a variable <tore@aursand.no>
    Re: how to reset a variable <jwillmore@remove.adelphia.net>
    Re: how to reset a variable (Novice)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Sat, 13 Mar 2004 22:50:55 +0530
From: Thens <thens@NOSPAMti.com>
Subject: Re: [OT] Re: Spreadsheet::WriteExcel - Excel 97 install problem
Message-Id: <20040313225055.1e8ad72a.thens@NOSPAMti.com>

On Fri, 12 Mar 2004 15:10:35 +0000 (UTC)
Ben Morrow <usenet@morrow.me.uk> wrote:

# 
# Quoth Bhaskar Reddy <rbin.kor901209@in.bosch.com>:
# > Thens <thens@NOSPAMti.com> wrote in 
# > news:20040312161200.6de7e876.thens@NOSPAMti.com:
# > 
# 
# Just 'cos I'm bored... (and I bet it's simpler than your Java one :):

Thanks !

But, cant you do away with the 'no warnings'

Regards,
Thens.

# #!/usr/bin/perl -l
# 
# # (c) 2004 Ben Morrow <ben@morrow.me.uk>
# # This program is in the public domain.
# 
# use warnings;
# use strict;
# 
# use subs qw(dirtree indent);
# 
# use constant INDENT => '|' . (' ' x 4);
# use constant NOMORE => ' ' x 5;
# use constant BRANCH => '|' . ('-' x 3) . ' ';
# use constant LAST   => '+' . ('-' x 3) . ' ';
# 
# sub indent {
#     return map { $_ ? INDENT : NOMORE } @_;
# }
# 
# sub dirtree {
#     my $dir = shift;
#     my $nldone;
# 
#     my @items = sort grep !/^\./, do {
#         opendir my $DIR, $dir or do {
#             print indent(@_), "ACCESS DENIED";
#             print indent(@_);
#             return 1;
#         };
#         readdir $DIR;
#     };
# 
#     while (defined($_ = shift @items)) {
#         my ($mark, $recurse);
#         no warnings 'uninitialized';
#         
#         if (-l "$dir/$_") {
#             $mark .= ' -> ' . readlink "$dir/$_";
#             -e "$dir/$_";          
#         }
#         elsif (-d _) { $recurse = 1 }
#         -d _           and $mark .= ' /';
#         -p _           and $mark .= ' |';
#         -S _           and $mark .= ' =';
#         (-c _ or -b _) and $mark .= ' #';
#         -x _ and -f _  and $mark .= ' *';
#         
#         print indent(@_), (@items ? BRANCH : LAST), $_, $mark;
#         $recurse and $nldone = dirtree "$dir/$_", @_, @items ? 1 : 0;
#         @items or $nldone or print indent(@_) and return 1;
#     }
#     return $nldone;
# }
# 
# my $dir = shift || '.';
# -d $dir or die "$dir: not a directory\n";
# print $dir;
# dirtree $dir;
# 
# __END__
# 
# Output like:
# 
# Acme-Abuse-0.02
# |--- Changes
# |--- MANIFEST
# |--- META.yml
# |--- Makefile.PL
# |--- README
# |--- SIGNATURE
# |--- lib /
# |    +--- Acme /
# |         +--- Abuse.pm
# |
# +--- t /
#      |--- 0-signature.t
#      |--- 1-Acme-Abuse.t
#      +--- Acme /
#           +--- Abuse /
#                +--- Test.pm *
# 
# The grep !/^\./ is a bit unixy: you may want to replace it with
# !/\.\.?/; and for proper portability I should have used File::Spec, but
# that makes such a mess of things :).
# 
# Ben
# 
# -- 
# And if you wanna make sense / Whatcha looking at me for?          (Fiona Apple)
#                             * ben@morrow.me.uk *


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

Date: 13 Mar 2004 12:36:04 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: C expressions in Perl
Message-Id: <c2uv7k$m1u$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tore Aursand:

> You could also define 'true' as a constant (although I would suggest that
> you uppercase all constants);
> 
>   use constant {
>       FALSE => 0,
>       TRUE  => 1,
>   };
> 
>   sub F {
>       return TRUE;
>   }

The suggestion of using symbol constants for a true and a false values
comes up periodically but doesn't make much sense in Perl. What you call
FALSE is actually true when being in list context. And since context is
a runtime thing, you cannot use a constant (at least) for FALSE.
Therefore don't even try.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: Sat, 13 Mar 2004 17:34:52 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: C expressions in Perl
Message-Id: <pan.2004.03.13.16.26.09.635731@aursand.no>

On Sat, 13 Mar 2004 12:36:04 +0000, Tassilo v. Parseval wrote:
>> You could also define 'true' as a constant (although I would suggest that
>> you uppercase all constants);
>> 
>>   use constant {
>>       FALSE => 0,
>>       TRUE  => 1,
>>   };
>> 
>>   sub F {
>>       return TRUE;
>>   }

> The suggestion of using symbol constants for a true and a false values
> comes up periodically but doesn't make much sense in Perl.

I'm aware of that, and that's the reason I never do it this way. :)  But,
just out of curiosity, would 'FALSE => undef' be any better?


-- 
Tore Aursand <tore@aursand.no>
"Nothing is certain but death and taxes. Of the two, taxes happen
 annually." -- Joel Fox


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

Date: 13 Mar 2004 17:48:45 GMT
From: "Tassilo v. Parseval" <tassilo.parseval@rwth-aachen.de>
Subject: Re: C expressions in Perl
Message-Id: <c2vhht$r3e$1@nets3.rz.RWTH-Aachen.DE>

Also sprach Tore Aursand:

> On Sat, 13 Mar 2004 12:36:04 +0000, Tassilo v. Parseval wrote:
>>> You could also define 'true' as a constant (although I would suggest that
>>> you uppercase all constants);
>>> 
>>>   use constant {
>>>       FALSE => 0,
>>>       TRUE  => 1,
>>>   };
>>> 
>>>   sub F {
>>>       return TRUE;
>>>   }
> 
>> The suggestion of using symbol constants for a true and a false values
>> comes up periodically but doesn't make much sense in Perl.
> 
> I'm aware of that, and that's the reason I never do it this way. :)  But,
> just out of curiosity, would 'FALSE => undef' be any better?

No, it's the same problem with undef. What you could probably do (but I
haven't thoroughly tested) is:

    use constant FALSE => ();

This will evaluate to false in list context.

Tassilo
-- 
$_=q#",}])!JAPH!qq(tsuJ[{@"tnirp}3..0}_$;//::niam/s~=)]3[))_$-3(rellac(=_$({
pam{rekcahbus})(rekcah{lrePbus})(lreP{rehtonabus})!JAPH!qq(rehtona{tsuJbus#;
$_=reverse,s+(?<=sub).+q#q!'"qq.\t$&."'!#+sexisexiixesixeseg;y~\n~~dddd;eval


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

Date: 13 Mar 2004 08:43:09 -0800
From: mjpliv@eastlink.ca (Martin L.)
Subject: extracting the contents of the <title> tag
Message-Id: <36fd063b.0403130843.1287be2e@posting.google.com>

Anyone know of a function that reads the contents of the <title> tag
into a variable once I open an HTML file.


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

Date: Sat, 13 Mar 2004 13:25:50 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: extracting the contents of the <title> tag
Message-Id: <pan.2004.03.13.18.25.49.120645@remove.adelphia.net>

On Sat, 13 Mar 2004 08:43:09 -0800, Martin L. wrote:

> Anyone know of a function that reads the contents of the <title> tag
> into a variable once I open an HTML file.

Use Google to search this group - it's been asked and answered before. 
Use the keywords 'html parse title'.

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
Character Density, n.:  The number of very weird people in the office. 



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

Date: Sat, 13 Mar 2004 11:29:16 -0700
From: Bill <wherrera@lynxview.com>
Subject: Re: extracting the contents of the <title> tag
Message-Id: <8KSdnc_Owviczs7dRVn-hg@adelphia.com>

Martin L. wrote:
> Anyone know of a function that reads the contents of the <title> tag
> into a variable once I open an HTML file.

untested:
======================
use strict;
use warnings;
use HTML::TreeBuilder;

my $tree = HTML::TreeBuilder->new;
my ($heading, $titletag);
my $html = 'myfile.html';
$tree->parse_file($html);
$titletag = $tree->look_down('_tag', 'title');
if($titletag) { $heading = $$titletag->as_text; }
else { die "No title in file found in $html: $!" }

$tree->delete;
print $heading;
=====================
--HTH



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

Date: Sat, 13 Mar 2004 12:50:20 GMT
From: "blnukem" <bill@hotmail.com>
Subject: File Creation From Form
Message-Id: <gsD4c.16754$Sp2.4499715@news4.srv.hcvlny.cv.net>

Hi All

I have a form on a Linux system that takes a file name from the user and
creates a file according to the name. The problem is if the user type in
something like Giclée it creates a file named gicl(-)es. If I test the code
locally with a defined variable of: my $NewPageName = "Giclée"; it works
fine. Any ideas?

Code:
#!/usr/bin/perl -w

use strict;
use CGI qw(:standard);

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

my $NewPageName = param('NewPageName');
$NewPageName = lc($NewPageName);
$NewPageName =~ tr/ \n\r\t//d;

open (TEXT, ">$NewPageName.txt") or die "Could not print the data: $!";
print TEXT "$NewPageName";
close(TEXT);

print "Done";



Thanks in advance
Blnukem




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

Date: Sat, 13 Mar 2004 14:41:36 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: File Creation From Form
Message-Id: <c2v3e6$21b2nb$1@ID-184292.news.uni-berlin.de>

blnukem wrote:
> I have a form on a Linux system that takes a file name from the
> user and creates a file according to the name. The problem is if
> the user type in something like Giclée it creates a file named
> gicl(-)es. If I test the code locally with a defined variable of:
> my $NewPageName = "Giclée"; it works fine. Any ideas?

You'd better validate the input string, and reject it if it contains
special characters. Something like:

     if ($NewPageName =~ /\W/) {
         print "<p>The file name may only contain a-z letters ",
               "and digits.\n<p>Please try again.\n";
         exit;
     }

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



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

Date: Sat, 13 Mar 2004 13:53:29 GMT
From: "blnukem" <bill@hotmail.com>
Subject: Re: File Creation From Form
Message-Id: <tnE4c.16833$Sp2.4681600@news4.srv.hcvlny.cv.net>

Gunnar

But I need to allow these characters.

Blnukem

"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:c2v3e6$21b2nb$1@ID-184292.news.uni-berlin.de...
> blnukem wrote:
> > I have a form on a Linux system that takes a file name from the
> > user and creates a file according to the name. The problem is if
> > the user type in something like Giclée it creates a file named
> > gicl(-)es. If I test the code locally with a defined variable of:
> > my $NewPageName = "Giclée"; it works fine. Any ideas?
>
> You'd better validate the input string, and reject it if it contains
> special characters. Something like:
>
>      if ($NewPageName =~ /\W/) {
>          print "<p>The file name may only contain a-z letters ",
>                "and digits.\n<p>Please try again.\n";
>          exit;
>      }
>
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>




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

Date: Sat, 13 Mar 2004 14:52:42 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: File Creation From Form
Message-Id: <c2v432$21e9mh$1@ID-184292.news.uni-berlin.de>

[ Please do not top post! ]

blnukem wrote:
> Gunnar Hjalmarsson wrote:
>> You'd better validate the input string, and reject it if it
>> contains special characters. Something like:
>> 
>>     if ($NewPageName =~ /\W/) {
>>         print "<p>The file name may only contain a-z letters ",
>>               "and digits.\n<p>Please try again.\n";
>>         exit;
>>     }
> 
> But I need to allow these characters.

As file names? Why would you need that?

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



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

Date: Sat, 13 Mar 2004 14:06:25 GMT
From: "blnukem" <bill@hotmail.com>
Subject: Re: File Creation From Form
Message-Id: <BzE4c.16890$Sp2.4729169@news4.srv.hcvlny.cv.net>


"Gunnar Hjalmarsson" <noreply@gunnar.cc> wrote in message
news:c2v432$21e9mh$1@ID-184292.news.uni-berlin.de...
> [ Please do not top post! ]
>
> blnukem wrote:
> > Gunnar Hjalmarsson wrote:
> >> You'd better validate the input string, and reject it if it
> >> contains special characters. Something like:
> >>
> >>     if ($NewPageName =~ /\W/) {
> >>         print "<p>The file name may only contain a-z letters ",
> >>               "and digits.\n<p>Please try again.\n";
> >>         exit;
> >>     }
> >
> > But I need to allow these characters.
>
> As file names? Why would you need that?
>
> -- 
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl
>

Gunnar

It needs to be exact name for latter use in a search. Let me add one other
thing when it "prints to the file" it prints Giclée It just wont save the
file as Giclée.

Blnukem






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

Date: Sat, 13 Mar 2004 15:25:30 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: File Creation From Form
Message-Id: <c2v5j1$2119i9$1@ID-184292.news.uni-berlin.de>

blnukem wrote:
> Gunnar Hjalmarsson wrote:
>> blnukem wrote:
>>> Gunnar Hjalmarsson wrote:
>>>> You'd better validate the input string, and reject it if it 
>>>> contains special characters. Something like:
>>>> 
>>>>    if ($NewPageName =~ /\W/) {
>>>>        print "<p>The file name may only contain a-z letters ",
>>>>              "and digits.\n<p>Please try again.\n";
>>>>        exit;
>>>>    }
>>> 
>>> But I need to allow these characters.
>> 
>> As file names? Why would you need that?
> 
> It needs to be exact name for latter use in a search.

Converting special characters to numeric values is another approach:

     $NewPageName =~ s/(\W)/ord $1/eg;

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



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

Date: Sat, 13 Mar 2004 08:23:14 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: File Creation From Form
Message-Id: <slrnc566ai.29r.tadmc@magna.augustmail.com>

blnukem <bill@hotmail.com> wrote:

> print TEXT "$NewPageName";
             ^            ^
             ^            ^ a useless use of double quotes


   print TEXT $NewPageName;


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


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

Date: Sat, 13 Mar 2004 14:20:25 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: File Creation From Form
Message-Id: <Pine.LNX.4.53.0403131352421.27560@ppepc56.ph.gla.ac.uk>

On Sat, 13 Mar 2004, blnukem wrote:

> I have a form on a Linux system that takes a file name from the user and
> creates a file according to the name. The problem is if the user type in
> something like Giclée it creates a file named gicl(-)es.

Handling anything more than us-ascii characters on HTML forms input is
a complex topic, and not (in itself) really a matter for
comp.lang.perl.misc - probably better dealt with in the CGI authoring
group, if you really, _really_ need it. [1]

> If I test the code locally with a defined variable of: my
> $NewPageName = "Giclée"; it works fine.

It would, that doesn't surprise me.  So the Perl part is working  ;-)

> Any ideas?

Do you actually _require_ to create such file names?  I dare to
suggest you've be better off, and surely safer, if you could factor
them out of the problem.

> Code:
> #!/usr/bin/perl -w
>
> use strict;
> use CGI qw(:standard);
>
> print "Content-type: text/html\n\n";
>
> my $NewPageName = param('NewPageName');
> $NewPageName = lc($NewPageName);
> $NewPageName =~ tr/ \n\r\t//d;
>
> open (TEXT, ">$NewPageName.txt") or die "Could not print the data: $!";

You've got most of this right, but the frightening thing is the one
vital bit that you've missed out.

You desperately, but *desperately* need to know how to handle tainted
data.  And to help you do that, it's *strongly* recommended to enable
taint checking (-T on the shebang line).

Don't put another CGI script anywhere near the public WWW until you've
grasped these principles, and implemented them in your scripts.  Read
Stein's CGI security FAQ, as well as the perlsec pod (perldoc
perlsec).

Once that's out of the way, you'll recognise that you need a regex
which is untainting the data that's coming from outside, i.e
allowing-through the allowed characters and keeping out the dangerous
ones, before attempting to use it for any system-critical purposes.

Usually the best strategy is to entirely reject values which contain
anything that you aren't willing to accept, and ask the user to try
again, rather than by stealthily filtering out stuff that you don't
care for and just using what's left.  However, there might be an
argument for silently turning accented letters into unaccented letters
and using the result, as long as that makes sense in the particular
context.

Remember, the key principle of security is only to accept what you
know to be safe (don't just try to filter out what you believe to be
dangerous).

Finally, if you're using CGI.pm, as you are, then I'd recommend using
its features.  Not hand-knitted stuff like
  print "Content-type: text/html\n\n";

There's a specific reason for that.  In the absence of an explicit
character encoding specification (charset=) for the HTML document,
forms submission of non-ascii characters is even more uncertain than
when it's specified.   So, tell CGI.pm what charset you intend to use
(be it utf-8 or be it iso-8859-1 or whatever) and use _it_ to create
the appropriate headers for you, including the "charset=" attribute.

take care

[1] there's a very incomplete survey on my page at
http://ppewww.ph.gla.ac.uk/~flavell/charset/form-i18n.html


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

Date: Sat, 13 Mar 2004 14:51:34 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: File Creation From Form
Message-Id: <Pine.LNX.4.53.0403131433050.27560@ppepc56.ph.gla.ac.uk>

On Sat, 13 Mar 2004, Gunnar Hjalmarsson wrote:

> Converting special characters to numeric values is another approach:

The O.P's first problem is that the script will get whatever the
browser submitted to the server, digested by the best efforts of
CGI.pm; not necessarily the "special"[1] characters that were typed
into the form.  And that's a whole can of worms, as my cited page only
begins to reveal.  Some browsers in some situations will submit a
single "special" character as something in the form &#1234; (a purely
ASCII character string - ampersand, hash[2], a decimal number,
semicolon), and that's not the only possibility.

N.B this is in no way a shortcoming of CGI.pm.  The problems are with
the definition of the form-submission mechanism, and various
implementers' attempts to extend the definition beyond its limits.
CGI.pm can only do the best it can with whatever gets thrown at it.

cheers

[1] I do hate that term "special characters".  It made sense back in
the days of ASCII, maybe even 8-bit codes such as iso-88591, but with
Unicode containing many thousands of characters, there's a sense in
which A-Z and 0-9 are more "special" than most of the others :-}

[2] pedantically, "NUMBER SIGN".  Let's not start on "octothorpe".


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

Date: Sat, 13 Mar 2004 18:50:04 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: File Creation From Form
Message-Id: <c2vhj7$22od3v$1@ID-184292.news.uni-berlin.de>

Alan J. Flavell wrote:
> The O.P's first problem is that the script will get whatever the 
> browser submitted to the server, digested by the best efforts of 
> CGI.pm; not necessarily the "special"[1] characters that were typed
> into the form.  And that's a whole can of worms, as my cited page
> only begins to reveal.

Well, my suggestions do imply various assumptions. I did not get the
impression that OP is creating a site for handling various charsets,
but that we are talking about iso-8859-1 characters. Accordingly I
assume that the variable is 'safely' assigned via URI
encoding/decoding the "special" (non-ASCII in this context) characters
that were typed into the form.

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



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

Date: Sat, 13 Mar 2004 18:11:51 +0000
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: File Creation From Form
Message-Id: <Pine.LNX.4.53.0403131759270.27560@ppepc56.ph.gla.ac.uk>

On Sat, 13 Mar 2004, Gunnar Hjalmarsson wrote:

> Well, my suggestions do imply various assumptions. I did not get the
> impression that OP is creating a site for handling various charsets,

Nevertheless, unless there's some factors here which we haven't been
told, he doesn't control the user's browser, and he's going to have to
field whatever the user's browser throws at him.

> but that we are talking about iso-8859-1 characters.

He's not presently setting charset=iso-8859-1 on his content-type
header; if the browser doesn't know what encoding (charset) to use,
then it's going to take whatever default the user has set it to.  If
that happens to be (e.g) utf-8, then there will be problems.

> Accordingly I assume that the variable is 'safely' assigned via URI
> encoding/decoding the "special" (non-ASCII in this context)
> characters that were typed into the form.

Even if the appropriate conditions are fulfilled for that (about which
you seem to have quite a lot more trust than I have), there's still
the question of what the browser will do when the user types - let's
say - a euro sign into their iso-8859-1 submission (since iso-8859-1
does not include a euro sign).

Sorry if I seem to be stubborn about this.


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

Date: Sat, 13 Mar 2004 13:17:37 GMT
From: mike <m.amedeo@NOSPAMatt.net>
Subject: help with HTTP::Daemon
Message-Id: <RRD4c.908$Q2.111@nwrdny03.gnilink.net>

If someone could point me on how to accomplish this. I do not want to 
run an entire webserver to give me information about a system. I written 
cgi scripts that I run under apache that will show filesystems, 
processes etc. But I was trying to write a perl script use HTTP::Daemon 
that will give me the output of a command say df -k, ps -ef on a 
browser. I tried many different thing with the script below but my 
browser connects but nothing is displayed. Can anyone provide some advice.

Thanks
Mike

#!/usr/bin/perl
use HTTP::Daemon;
my $http = HTTP::Daemon->new ( LocalPort => 8200);
print $http->url;
while (my $connect = $http->accept) {
$connect->send_response(`df -k`);

          }
          $connect->close;
          undef $connect;



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

Date: Sat, 13 Mar 2004 13:20:14 +0100
From: Tore Aursand <tore@aursand.no>
Subject: Re: how to reset a variable
Message-Id: <pan.2004.03.13.12.20.07.677929@aursand.no>

On Sat, 13 Mar 2004 05:27:53 -0500, James Willmore wrote:
> foreach my $line(@lines){
>     print "$line\n" if /^someTextImParsingOnANewLine/;
> }

Uhm.  This won't work, as your regexp tries to examine $_.  This is,
however, the best (yeah) solution, IMO;

  foreach ( @lines ) {
      print $_ if ( /^someTextImParsingOnANewLine/ );
  }


-- 
Tore Aursand <tore@aursand.no>
"Why shouldn't truth be stranger than fiction? Fiction, after all, has
 to make sense." -- Mark Twain


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

Date: Sat, 13 Mar 2004 11:21:44 -0500
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: how to reset a variable
Message-Id: <pan.2004.03.13.16.21.42.737418@remove.adelphia.net>

On Sat, 13 Mar 2004 13:20:14 +0100, Tore Aursand wrote:

> On Sat, 13 Mar 2004 05:27:53 -0500, James Willmore wrote:
>> foreach my $line(@lines){
>>     print "$line\n" if /^someTextImParsingOnANewLine/;
>> }
> 
> Uhm.  This won't work, as your regexp tries to examine $_.  This is,
> however, the best (yeah) solution, IMO;
> 
>   foreach ( @lines ) {
>       print $_ if ( /^someTextImParsingOnANewLine/ );
>   }

After getting some sleep and seeing the code with clear eyes .... you're
100% correct.

Sorry for posting poop :-(

-- 
Jim

Copyright notice: all code written by the author in this post is
 released under the GPL. http://www.gnu.org/licenses/gpl.txt 
for more information.

a fortune quote ...
A free society is one where it is safe to be unpopular.   -- Adlai
Stevenson 



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

Date: 13 Mar 2004 08:41:47 -0800
From: 6tc1@qlink.queensu.ca (Novice)
Subject: Re: how to reset a variable
Message-Id: <b80e4a77.0403130841.7ecaeb38@posting.google.com>

Thanks to everyone.

Note to:
Jay Tilton (tiltonj@erols.com)
Tore Aursand (tore@aursand.no)
James Willmore (jwillmore@remove.adelphia.net)

This code does not exist in any program of mine.  This code is an
example of a small subset of the logic that exists in my code.  There
are no variables name "someScalarVar" in my code, etc.  I pulled out
everything in my code that wasn't relevant to my question.

What I should have written in my original post is:

Code excerpt:
#------------------------
for ($iterator = 0; $iterator <= $#lines; $iterator++)
{
  $line = @lines[$iterator];
  $_ = $line;

  $someScalarVar;

  if (/^someTextImParsingOnANewLine/)
  {
    $someScalarVar = $line;
    #after assigning - parse the text contained in somScalarVar
  }
  #additional conditional else if's that test for other regular
expressions

  #process contents of someScalarVar if it contains any data/text 

}
#------------------------

So I guess the answer I'm looking for is to:
Assign the variable someScalarVar to undef

I wasn't aware of the localization that "my" imposes - I just went
through the "standard beginner's introduction to Perl" at:
http://www.comp.leeds.ac.uk/Perl/start.html

The above website is duplicated on about 10 or more different sites -
I don't know where the official version resides.

But after seeing a couple of you reference the my keyword, I looked
here:
http://www.extropia.com/tutorials/perl5/localizing.html
for the explanation.  

Thanks everyone,
Novice

PS Good call Tore - I'm from the C and C++ world - my Perl is thus
perhaps more convoluted than necessary.


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

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


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