[16677] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4089 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 22 00:05:28 2000

Date: Mon, 21 Aug 2000 21:05:13 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <966917112-v9-i4089@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 21 Aug 2000     Volume: 9 Number: 4089

Today's topics:
    Re: A puzzle: Can't find the syntax error in this regex <tim@ipac.caltech.edu>
    Re: A puzzle: Can't find the syntax error in this regex (Keith Calvert Ivey)
    Re: Check for Installed Modules <r28629@email.sps.mot.com>
    Re: crypt function (Keith Calvert Ivey)
    Re: exists() before 5.6 for sub's <tim@ipac.caltech.edu>
    Re: find printers in win2000 <bwalton@rochester.rr.com>
        Forking in WinNT reedjd@bitsmart.com
    Re: Forking sub{}'s and selective SIG{CHLD} responses (Gwyn Judd)
        Functions and reference notation. johnvert@my-deja.com
    Re: Help: Excel Automation question! <bwalton@rochester.rr.com>
    Re: newline and carriage return problems <elephant@squirrelgroup.com>
        Parse::Recdescent questions (<commit> and other problem <ocschwar@mit.edu>
    Re: Regex <tim@ipac.caltech.edu>
    Re: regexing html-like tags <blair@geo-NOSPAM-soft.org>
    Re: regexing html-like tags <godzilla@stomp.stomp.tokyo>
    Re: regexing html-like tags <godzilla@stomp.stomp.tokyo>
    Re: system() output screwing up redirection. <kheunc@yahoo.com>
    Re: system() output screwing up redirection. (Malcolm Dew-Jones)
    Re: system() output screwing up redirection. <philipg@atl.mediaone.net>
    Re: system() output screwing up redirection. swan_daniel@my-deja.com
    Re: Template In/File Out <tim@ipac.caltech.edu>
    Re: Updating textfile problem... <tim@ipac.caltech.edu>
    Re: Updating textfile problem... <tim@ipac.caltech.edu>
    Re: Updating textfile problem... (Keith Calvert Ivey)
    Re: Variable vanishing? <abe@ztreet.demon.nl>
        WIN32:OLE and Excel: Approach to printing cell formulas blavagna@my-deja.com
    Re: WIN32:OLE and Excel: Approach to printing cell form <bwalton@rochester.rr.com>
    Re: would you recommend buying a book <elephant@squirrelgroup.com>
    Re: would you recommend buying a book <katz@underlevel.net>
    Re: would you recommend buying a book <bwalton@rochester.rr.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Mon, 21 Aug 2000 19:43:36 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: A puzzle: Can't find the syntax error in this regex?!?
Message-Id: <39A1E8D8.DBA39A85@ipac.caltech.edu>

Burton Kent wrote:
> 
> I'm stumped.  What am I doing wrong, as this won't compile?
> 
> ... code snipped ...
>                 if ($lc_attributes{$thing}) {
>                         $thing = "_" . $lc_attributes{$thing} . "_";
>                 }
>                 elif ( $lc_elements{$thing} ) {  # Line 16
> ... etc ...

The first error message (which it would have been nice of you to include) is
really very helpful: syntax error at - line 16, near ") {".

'elif' is not a perl keyword. You want 'elsif'.

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Tue, 22 Aug 2000 02:08:15 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: A puzzle: Can't find the syntax error in this regex?!?
Message-Id: <39a3df66.7943652@news.newsguy.com>

Burton Kent <burton@remove_this.lucent.com> wrote:

>my $ELEMENT_REGEX = "[A-z][A-z0-9-]*";

Others have pointed out some of the other problems with your
program, but I this line leapt out at me.  I doubt that A-z is
the range you want, since it includes some nonalphabetic
characters -- [\]^_` -- that you're probably not expecting.
You want A-Za-z instead.

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Tue, 22 Aug 2000 09:09:02 +0800
From: Tk Soh <r28629@email.sps.mot.com>
To: marcel@codewerk.com
Subject: Re: Check for Installed Modules
Message-Id: <39A1D2AE.5AF70B13@email.sps.mot.com>

[posted and cc'ed]

Marcel Grunauer wrote:
> 
> For use on the command-line, there is the pminst program,
> part of pmtools written by Tom Christiansen. Download it from
> http://doriath.perl.com/misc/pmtools-1.00.tar.gz
> 

just what I have been looking for. I asked the question once awhile ago,
but didn't get the right answer. Thanks a bunch.

-TK


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

Date: Tue, 22 Aug 2000 00:42:14 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: crypt function
Message-Id: <39a1ca0d.2477873@news.newsguy.com>

mjd@plover.com (Mark-Jason Dominus) wrote:
>Keith Calvert Ivey <kcivey@cpcug.org> wrote:

>>(assuming it doesn't find another string instead that
>>produces the same crypted version).
>
>If it does, that's OK, because such a string will work just as well as
>the true password.

True, but the user receiving the e-mailed password might think
'Strange, I don't remember choosing "&\xe7?\x9b\x3f\t\xef\xb7"
as my password, and how do I type it?'

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Mon, 21 Aug 2000 20:10:29 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: exists() before 5.6 for sub's
Message-Id: <39A1EF25.BF84A37B@ipac.caltech.edu>

Jerrad Pierce wrote:
> 
> Does anybody know of a way to emulate:
>         exists &foo;
> functionality in a pre 5.6 build?

One way is something like

sub there {
  no strict; 
  my $sub = shift;
  *$sub{CODE};
}

$sub = "foo";
print "$sub not there\n" if not there($sub);

> PS> Please (b) cc me with any replies

Sorry, you'll just have to read the newsgroup.

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Tue, 22 Aug 2000 03:39:20 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: find printers in win2000
Message-Id: <39A1F618.70F8D76C@rochester.rr.com>

richard_rader@my-deja.com wrote:
> 
> I am trying to find an easy way to get a list of printers on a win2000
> system. I am dreaming of creating a simple TK Gui to select a valid
> printer, then issue a system command to "enscript". I have found
> NetResource to get all printers, but i want only the ones already
> installed on my machine (ie ones i can print to)
> 
> I found the Win32::API to access comdlg32, then the user can select the
> printer. I can grab that printer name and go with that, but what i
> really want is just a way to get those printer names myself.
> 
> I tried Enum, but i am FAR from a windows expert.
> 
> This has got to be easier than i am making it
> 
> thanks
> rader
 ...

Assuming Windoze 2000 is like the other Windoze's, you could fire off a
"net view \\computername" command and parse its output for lines
containing a Type of Print:

    for(`net view \\\\computername`){
        push @printers,$1 if /^(\w+)\s+Print/;
    }

-- 
Bob Walton


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

Date: Tue, 22 Aug 2000 01:09:02 GMT
From: reedjd@bitsmart.com
Subject: Forking in WinNT
Message-Id: <8nsjr2$s3b$1@nnrp1.deja.com>

I'm having problems getting a forking application to work in WinNT with
ActivePerl "This is perl, v5.6.0 built for MSWin32-x86-multi-thread"

When I run the following App, I get Dr. Watson crash:
could not attache to the application
Windows NT Error Code = 87

Code:
my $ua = new LWP::UserAgent();
FORK: for($requestKount=1; $requestKount <= 5; $requestKount++) {
  if($pid = fork) {
    print "$$: next FORK\n";
    next FORK;
  } elsif (defined $pid) {
    print "$$: Requesting\n";
    $requestResult = $ua->request(GET "http://www.cnn.com");
    print "  $$: Got\n";
    goto DONE;
  }
}
print "$$: AllDone\n";
#wait;
sleep;
print "$$: Done Waiting\n";
DONE:



Output Snippet:
589: next FORK
589: next FORK
-337: Requesting
589: next FORK
589: next FORK
589: next FORK
589: AllDone
  -337: Got
589: Done Waiting
-472: Requesting
  -472: Got

-jr


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 22 Aug 2000 03:28:04 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: Forking sub{}'s and selective SIG{CHLD} responses
Message-Id: <slrn8q3sq2.al.tjla@thislove.dyndns.org>

I was shocked! How could Martien Verbruggen <mgjv@tradingpost.com.au>
say such a terrible thing:
>On Mon, 21 Aug 2000 05:22:10 GMT,
>	Gwyn Judd <tjla@guvfybir.qlaqaf.bet> wrote:
>> I was shocked! How could Martien Verbruggen <mgjv@tradingpost.com.au>
>> say such a terrible thing:
>> >[reorganised order of post to respect the normal arrow of time]
>
>Hmmm. You really think this statement was that horrible?

No...worse

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Most people will listen to your unreasonable demands, if you'll consider
their unacceptable offer.


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

Date: Tue, 22 Aug 2000 03:14:42 GMT
From: johnvert@my-deja.com
Subject: Functions and reference notation.
Message-Id: <8nsr6l$455$1@nnrp1.deja.com>

Hello comp.lang.perl.misc,

I have two and a half questions that are unrelated to each other (one
and a half on functions, and one on reference notation), but since
they're short I'll include them in the same post:

1.  My Perl book ($Learning Perl$ by Schwartz and Christiansen) uses the
words ``function'' and ``operator'' pretty much interchangeably, i.e.
``The open() operator'', which seems weird to me.  Is it correct to use
these terms interchangeably in Perl?

1a. Most built-in functions I've used in Perl, as well as the ones I
wrote can be used with or without parenthesis.  However, I ran into a
number of functions (the only ones that come to mind now are the ones
from the Gtk-Perl package, but there were more examples) that required
parenthesis and otherwise would not compile.  Why is that?  I have a
feeling it's related to a precedence issue, but I'm not sure.

2. I know that the -> operator can be used to make dereferencing look
less ugly, i.e. writing:

my @array = (1, 2, 3, 4, 5);
my $arrayref = \@array;

print $arrayref->[0] . "\n";

instead of:

print @$arrayref[0] . "\n";

but recently I've seen it used like this:

%ENV->{SHELL}; instead of the more familiar (to me): $ENV{SHELL};

AFAIK, 'ENV' isn't a reference (otherwise why would $ENV{SHELL} work?),
so I was hoping someone could explain this syntax (or refer me to the
right docs.)

Thanks a lot for your patience with a newbster,
 -- john


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 22 Aug 2000 03:13:17 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: Help: Excel Automation question!
Message-Id: <39A1EFFC.5FB6F355@rochester.rr.com>

ajeet@my-deja.com wrote:
 ...
> I am trying to use Win32::OLE to extract data from a MS Excel sheet.
> Once, I open the workbook, I do this to access the values:
> $worksheet = $workbook->Worksheets($sheetNo);
> $thisref = $worksheet->Range("A4:A24")->{'Value'};
> 
> I have no problem with this, but it returns the exact values in the
> cells A4:24. What I NEED are the FORMATTED values in the cells. The
> documentation for the module says that I can access the TEXT-ONLY using
> this:
> $thisref = $worksheet->Range("A4:A24")->{'Text'};
> 
> But, all I get is an empty array. Anyone, who's done this before, could
> please help me? Thank you very much!
 ...
> Ajeet
 ...

I think you'll need to grab the text strings one at a time.  Something
like:

   $texta4=$worksheet->Range("A4")->Text;
   $texta5=$worksheet->Range("A5")->Text;
   ...

or maybe

   for $i (4..24){
      push @text,$worksheet->Range("A$i")->Text;
   }

One might assume that since 'Value' will return an array of arrays of
values that 'Text' would return an array of arrays of strings, but that
assumption would be wrong.  Excel doesn't DWIM.  Note that if you do use
'Value' and specify a one-cell range, you *don't* get an array of
arrays, but just a single value as a scalar.  That's a "feature" of
Excel, not Win32::OLE.  How wonderful, huh?
-- 
Bob Walton


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

Date: Tue, 22 Aug 2000 03:09:32 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: newline and carriage return problems
Message-Id: <MPG.140c8c5ba4c482b39896d6@localhost>

  [ posted to comp.lang.perl.misc and CCed to originator ]

I've been reading through this thread I think you've sufferred enough 
*8^) .. it would seem that everyone has read the subject line of your 
post and nothing else (then you started posting upside down and that got 
you in even more trouble)

so .. here goes

flanagab@hqamc.scott.af.mil <flanagab@hqamc.scott.af.mil> wrote ..
>I'm trying to do some simple processing of a HTML document's forms.
>All of the data has been passed to a Perl script by the standard POST
>method.  I have no problems except with the TEXTAREAs.  These can
>contain carriage returns (actually CR LF) within the box.
>
>I'm trying to write the output of the form to a data file in
>tab-delimited form.  The trouble is that the LF is being interpreted as
>a newline.  I figured, no problem, I'll strip the \x0A from the strings
>before I write them to the file, however, when I tried to do this, they
>would NOT go away!

probably because you're on a Win32 system (guess based on your article 
headers) and you haven't binmoded the output handle .. type the 
following at the command line to see documentation on binmode

  perldoc -f binmode

>I tried to split the string and chomp off the newline.  It came back.  I
>tried to split the string and chop off the newline, this chopped off
>BOTH the \x0D and \x0A from the string.  The trouble here is, I want to
>KEEP the \cM.  I only want to be rid of the \cJ.

here's some sample code

  my $string = "blah\cM\cJblah\cM\cJblah\cM\cJ";

  open OUTPUT, ">file" or die "Bad open: $!";
  binmode OUTPUT;

  print OUTPUT $string;

  close OUTPUT or die "Bad close: $!";

now .. file will contain the exact sequence of CRLFs in the above string 
 .. wanna strip off just the LFs

  my $string = "blah\cM\cJblah\cM\cJblah\cM\cJ";

  open OUTPUT, ">file" or die "Bad open: $!";
  binmode OUTPUT;

  $string =~ s/\cJ//g;

  print OUTPUT $string;

  close OUTPUT or die "Bad close: $!";

now .. file will contain

  "blah\cMblah\cMblah\cM"
  
>I also tried going ahead and chopping off both characters, and then
>reassembling the string, and appending the \x0D characters  to each
>section of the string.  The string comes back with \x0d \x0a instead.
>
>When I attempt a logical expression to search and replace on the string,
>it will find the 0A, but it inserts it back in along with my replacement
>string.
>
>In summation, I can get rid of the \x0a characters, but not without
>getting rid of the \x0d characters as well.  No matter what I try, the
>\x0a charaters won't go away.  Is there some switch or
>configuration setting to correct this problem?  Does anyone have any
>ideas?!

I still don't know why you want to leave the CRs in there .. but I'm 
assuming that there's some logical reason

HTH

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: Tue, 22 Aug 2000 03:53:44 +0000
From: Omri Schwarz <ocschwar@mit.edu>
Subject: Parse::Recdescent questions (<commit> and other problems.)
Message-Id: <39A1F948.B354F80B@mit.edu>

Greetings, all!

So, http://www.mit.edu/~ocschwar/decss2.pl is looking mighty good,
in that 1. I figured out how to make the C Grammar From Hell
correct in relation to things like multiplicative_expression
and 2. it isn't crashing completely.

But there are problems. When parsing 

int ijkton(int i, int j, int k){
  return i+I*(j-1)+I*J*(k-1);
}

it seems to get into an infinite loop. by segregating STDERR into
another
terminal you will see that it tries to evaluate the RETURN: rule at
least
twice. (It has to run for hours for this to show.)

Which makes me wonder if it is possible to make RecDescent parse
correctly with rules like

operator_expression_1 : (operator_expression_2 operator_1
operator_expression_2)(?s) 
     operator_expression_2

or whether that is doomed.

I'd be gratefull for any insight.

Next question:

I can do 

jump_statement : RETURN 
	| GOTO
	| BREAK

or I can do 

jump_statement : 'return' <commit> expression ';'
	| 'goto' <commit> .........

in order to trim the tree a little.

Can one add <commit> to the first version and
achieve anything?

Final question:

Is it possible to tell RecDescent to split its
input text to smaller chunks in order to speed performance?
(Would it speed performance?)


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

Date: Mon, 21 Aug 2000 19:25:58 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Regex
Message-Id: <39A1E4B6.C7E8CF85@ipac.caltech.edu>

Thomas Hutchings wrote:
> foreach (split /\n/, $buffer)
> {
>     if (/^START/) {
>        print "Starting buffer line\n";
>     }
>     next if //;
>     ..... # more processing
> }
> 
> My question concerns the "next if //" line.  As I read it, this should
> always match, rendering the remainder of the loop code useless.  In
> practice, though, it does not.  I assume the author intended "next if /^$/",
> which isn't equivalent, right?

From perlop:

              If the PATTERN evaluates to the empty string, the
              last successfully matched regular expression is
              used instead.


--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Tue, 22 Aug 2000 02:24:39 GMT
From: "Blair Heuer" <blair@geo-NOSPAM-soft.org>
Subject: Re: regexing html-like tags
Message-Id: <Hvlo5.107$Iw.179@newsread2.prod.itd.earthlink.net>

> > Say I have:
> >     $template = "[out name=bob age="44" comment="This is my comment!"];
# Just a random tag using possible syntax

> It would have been more helpful to use valid Perl syntax.  I've repaired
this below.

Oops! Sorry, I should have checked over that, but I just typed it out not
thinking.

> > Thats as simple and "clear" as I can put it.
>
> It was pretty clear along, for those who chose to read.

Thanks. That one sentence took my anger and bitterness way down. :)

> Here is a regex that handles the cases you've shown.  The only
> interesting part is that which looks for the ends of the values, which
> is rather ad hoc.  Poorly formatted or erroneous data can mess this up
> mightily.  I'm sure there is a module that does it better.
>
>
> #!/usr/bin/perl -w
> use strict;
>
> $_ = '"[out name=bob age="44" comment="This is my comment!"]';
>
> my %h;
>
> $h{$1} = $3 while /(\w+)=("?)(.+?)\2(?=\s+\w+=|]|$)/g;

That is perfect! It gets the job done. True, it could lead to erronous
output, and since the templates will be made by visitors to the site (its
for a multi-user message board system that uses templates), I should and
will look into improving upon it. It's a great starting off point, since
where I was before was no where close to this. There is a 'template' module
which might be able to do the job better, I'll have to look into it further.

Thank you very much for your help, and not just spitting out a "you are so
stupid" reply. :)

-Blair Heuer

P.S. Sorry for accidentily emailing this to your email address. I hit the
wrong button and did not realize it until it was too late to stop the mail
from going. I would have emailed saying "Oops" but I figure that would just
be more of a hassle. "Oops." :)




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

Date: Mon, 21 Aug 2000 20:11:29 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regexing html-like tags
Message-Id: <39A1EF61.5E929AF1@stomp.stomp.tokyo>

Blair Heuer wrote:

 
> > > I am trying to write a regular expression that is able to parse a
> > > variable for "tags" and return the tag attributes and values.

This is comprehensible and, only this. However, you cannot
write an effective and efficient single regex to accomplish
this task. This you already know, yes?


> > (snipped)

> > Reads to me you are making this as difficult as possible.
> > Your wording is so unclear, it is impossible to ascertain
> > what you want to do, with any confidence.

> > Nonetheless, this very simple skeleton test script below can
> > be modified to do whatever it is you want to do, which you
> > are apparently unable to explain clearly and concisely.
 
> Sheesh, its either one end of the spectrum or the other on this newsgroup:
> "not enough information", "too little information."


I did not say "not enough...." nor did I say "too little...."

I said you have not explained what you want, clearly and concisely.
Pay attention and give some thought to what you want to write
well before wetting the paper with quill ink. You still have
not explained clearly and concisely what you want. Bonehead
English would be an appropriate course of study for you.
This will supplement your graduate status from The Sears,
Roebuck & Company Academy Of Language Arts.


 
> That skeleton in no way does anything what I need.

My skeleton script does exactly what you want per
your stated parameters, at least those parameters
which are comprehensible. Appears you lack enough
experience in Perl programming to realize my small
script does not only what you want, but more. 

It also appears you expect to be served all you want
on a well polished silver platter. You will be
quite lucky to have me serve you with a paper plate.
You will be even more lucky if I don't severely beat
you with my kitchen spatula.



> I will shorten my query with the hopes of making it 
> easier to understand 

It is my long experience as a woman, shorter is
quite often not better.


(if you say too little information.... I will kill you :) ).

My boyfriend, an amateur boxer and a university professor, 
has been training me in boxing, in martial arts and in
mind munching for well over a decade now. You may find 
killing me, to be quite challenging, especially with my 
having survived the mean streets of East L.A. during my 
teenage and young adult years.

You will not survive my mind munching, Chollo Loco.

 
> Say I have:

Your unconscious use of idioms in writing beguiles you everytime.
Concealment of writing style is best left to well educated experts
such as myself.



>     $template = "[out name=bob age="44" comment="This is my comment!"]; #


This snippet is a joke, right? Ha. Ha. Funny. * rolls eyes *

 
> What should I do to put the name/value pairs of that tag (name: bob, age:
> 44, comment: This is my comment! ) into a hash.


You do mean an associative array, correct? 
Hash is what I serve coyotes around here.


Do you see,

"Idjit Slave Girl"

tattooed on my forehead? Figure out how to do this yourself.
While you are figuring this out, silently and repeatedly chant,

"Kira is a superior programmer than myself, as always and as always be."


Godzilla!



TEST SCRIPT:
____________

#!/usr/local/bin/perl

print "Content-Type: text/plain\n\n";

$string = '<html>Gobbly Gook<name=test1 value=test1> Gibberish<P
><NAME="TEST2" VALUE="TEST2">Techno-Geekster Gobbly Gibberish<name=
"test3" value="test3">Kira Is Brilliant<IMG SRC="Kira_Naked.gif">
Mule Manure Here<font face="test4" color="test4" size="test4"><BR>
Dr. Frankie Einstein Wrote This<FORM ACTION="Yo Ho!" METHOD="CRASH">
<FORM ACTION="//la.znet.com/~callgirl/"><INPUT TYPE="submit" VALUE
="CallGirl Nude Pictures"></FORM>YIKES!</html>';

$string =~ s¡\n|"¡¡g;
$string =~ s¡<([/\w]+)>¡¡g;
$string =~ s¡>¡>¦¡g;

@Array = split (/¦/, $string);

foreach $element (@Array)
 {
  if ($element =~/(<[^>]+>)/)
   {
    $element = $1;
    $element =~ s¡<|>¡¡g;
    $element =~ s¡=¡¦¡g; #optional delimiter
    print "$element\n";
   }
 }

exit;



PRINTED RESULTS:
________________

name¦test1 value¦test1
NAME¦TEST2 VALUE¦TEST2
name¦test3 value¦test3
IMG SRC¦Kira_Naked.gif
font face¦test4 color¦test4 size¦test4
FORM ACTION¦Yo Ho! METHOD¦CRASH
FORM ACTION¦//la.znet.com/~callgirl/
INPUT TYPE¦submit VALUE¦CallGirl Nude Pictures


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

Date: Mon, 21 Aug 2000 20:49:29 -0700
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: regexing html-like tags
Message-Id: <39A1F849.770E9E4A@stomp.stomp.tokyo>

Someone wrote:

> #!/usr/bin/perl -w
> use strict;
 
> $_ = '"[out name=bob age="44" comment="This is my comment!"]';
 
> my %h;
 
> $h{$1} = $3 while /(\w+)=("?)(.+?)\2(?=\s+\w+=|]|$)/g;
 
> print map "$_ => $h{$_}\n"  => sort keys %h;
 
> __END__
 
> Output:
 
> age => 44
> comment => This is my comment!
> name => bob
 





ROSLER TEST SCRIPT:
___________________


#!/usr/local/bin/perl

print "Content-Type: text/plain\n\n";

$_ = '<html>Gobbly Gook<name=test1 value=test1> Gibberish<P
><NAME="TEST2" VALUE="TEST2">Techno-Geekster Gobbly Gibberish<name=
"test3" value="test3">Kira Is Brilliant<IMG SRC="Kira_Naked.gif">
Mule Manure Here<font face="test4" color="test4" size="test4"><BR>
Dr. Frankie Einstein Wrote This<FORM ACTION="Yo Ho!" METHOD="CRASH">
<FORM ACTION="//la.znet.com/~callgirl/"><INPUT TYPE="submit" VALUE
="CallGirl Nude Pictures"></FORM>YIKES!</html>';

my %h;

## changed ] to > in this snippet:

$h{$1} = $3 while /(\w+)=("?)(.+?)\2(?=\s+\w+=|>|$)/g; 

print map "$_ => $h{$_}\n"  => sort keys %h;

exit;


PRINTED RESULTS:
________________

ACTION => //la.znet.com/~callgirl/
METHOD => CRASH
NAME => TEST2
SRC => Kira_Naked.gif
VALUE => TEST2
color => test4
face => test4
name => test1
size => test4
value => test3



Originating author indicated "tags" in a template
or a string, something, input of sorts, whatever.
He did not indicate a single tag, with serious syntax 
errors at that, as shown in his example. Tags is plural
Rosler, indicating any possible combination of "tags" 
is likely, whatever the Hades this author means by tags.

Really should work on your reading comprehension, Rosler,
just as this originating author should work on his
writing skills and communicative skills.


Shirley he will figure out how to handle [ ] versus < >.

Your script fails a reality test. Ahh... such are the
pitfalls in Xah's Perl Perl Land.


* demure smile *

Godzilla!


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

Date: Mon, 21 Aug 2000 09:27:36 -0400
From: bany1 <kheunc@yahoo.com>
Subject: Re: system() output screwing up redirection.
Message-Id: <39A12E47.5B7580DB@yahoo.com>

Hello,
Have you tried using the backticks such as:
$whoami=`whoami`;

Hope this helps.

swan_daniel@my-deja.com wrote:

> And as an addendum, I also tried the following format:
>
> system("/usr/local/bin/ipacsum --timeframe \"$forminput\"  --gif
> $TRAFDIR --gif-index /home/httpd/html/traffic/index${time}.html --png-
> caption-in-index  --png-asis --fixed-quantity M --png-height 480 --png-
> width 640 2>&1 > /dev/null");
>
> -This simply didn't execute.
>
> Thoughts?
>
> In article <8nscsd$k7p$1@nnrp1.deja.com>,
>   swan_daniel@my-deja.com wrote:
> > system() output??  I must be crazy!  From what I understand, system()
> > has no output other than a return code.
> >
> > Here's the lines in question:
> >
> > print "Location: http://$IPADDR/traffic/index${time}.html", "\n\n";
> >
> > system("/usr/local/bin/ipacsum --timeframe \"$forminput\"  --gif
> > $TRAFDIR --gif-index /home/httpd/html/traffic/index${time}.html --png-
> > caption-in-index  --png-asis --fixed-quantity M --png-height 480 --
> png-
> > width 640 2>&1 > /dev/null");
> >
> > The web browser out put reads "Internal server error..."
> >
> > /var/log/httpd/error_log reads "malformed header from script. Bad
> > header=IP accounting summary: /home/httpd/cgi-bin/ipac.cgi"
> >
> > Somehow, output from the script is getting back and screwing with my
> > redirection.  So I tried an alternate format:
> >
> > @ipacsum=("/usr/local/bin/ipacsum"," --timeframe"," today"," --gif","
> > $TRAFDIR"," --gif-
> > index"," /home/httpd/html/traffic/index${time}.html\n"," 2>&1","
> > >"," /dev/null");
> > system(@ipacsum);
> >
> > Still the same thing.  perldoc -f system wasn't of much help, and I
> > havn't found anything like this in the dejanews archives...
> >
> > Anyone have any ideas?
> >
> > Thanks in advance,
> > Dan.
> >
> > Sent via Deja.com http://www.deja.com/
> > Before you buy.
> >
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.



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

Date: 21 Aug 2000 18:11:21 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: system() output screwing up redirection.
Message-Id: <39a1d339@news.victoria.tc.ca>

swan_daniel@my-deja.com wrote:
: system() output??  I must be crazy!  From what I understand, system()
: has no output other than a return code.

: Here's the lines in question:

: print "Location: http://$IPADDR/traffic/index${time}.html", "\n\n";

: system("/usr/local/bin/ipacsum --timeframe \"$forminput\"  --gif
: $TRAFDIR --gif-index /home/httpd/html/traffic/index${time}.html --png-
: caption-in-index  --png-asis --fixed-quantity M --png-height 480 --png-
: width 640 2>&1 > /dev/null");

: The web browser out put reads "Internal server error..."

What displays when the script is run from the command prompt instead
of via a web browser?




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

Date: Tue, 22 Aug 2000 02:39:27 GMT
From: "Philip Garrett" <philipg@atl.mediaone.net>
Subject: Re: system() output screwing up redirection.
Message-Id: <zJlo5.55976$rd1.10347041@typhoon-news1.southeast.rr.com>

<swan_daniel@my-deja.com> wrote in message
news:8nscsd$k7p$1@nnrp1.deja.com...
<snip>
> system("/usr/local/bin/ipacsum --timeframe \"$forminput\"  --gif
> $TRAFDIR --gif-index /home/httpd/html/traffic/index${time}.html --png-
> caption-in-index  --png-asis --fixed-quantity M --png-height 480 --png-
> width 640 2>&1 > /dev/null");

Try putting "2>&1" _after_ "> /dev/null".

HTH
Philip





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

Date: Tue, 22 Aug 2000 03:09:28 GMT
From: swan_daniel@my-deja.com
Subject: Re: system() output screwing up redirection.
Message-Id: <8nsqss$41g$1@nnrp1.deja.com>

This did help, Philip, but now the script executes fine, but the system
function is not executed... I can tell, because the web pages it is
suppost to create do not exist.

In fact, I note that niether system function is executed by the CGI.

When I run it from the command line, however, it seems to work ok.  But
run as a CGI, the system()'s are ignored.

Here is the line I am working off of now:

system("/usr/local/bin/ipacsum --timeframe \"$forminput\"  --gif
$TRAFDIR --gif-index /home/httpd/html/traffic/index${time}.html
--png-caption-in-index  --png-asis  --fixed-quantity M --png-height 480
--png-width 640 > /dev/null 2>&1");

Thoughts?


Thanks also to Malcolm and bany1, for your help.







In article <zJlo5.55976$rd1.10347041@typhoon-news1.southeast.rr.com>,
  "Philip Garrett" <philipg@atl.mediaone.net> wrote:
> <swan_daniel@my-deja.com> wrote in message
> news:8nscsd$k7p$1@nnrp1.deja.com...
> <snip>
> > system("/usr/local/bin/ipacsum --timeframe \"$forminput\"  --gif
> > $TRAFDIR --gif-index /home/httpd/html/traffic/index${time}.html
--png-
> > caption-in-index  --png-asis --fixed-quantity M --png-height 480
--png-
> > width 640 2>&1 > /dev/null");
>
> Try putting "2>&1" _after_ "> /dev/null".
>
> HTH
> Philip
>
>


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Mon, 21 Aug 2000 20:13:58 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Template In/File Out
Message-Id: <39A1EFF6.308E372C@ipac.caltech.edu>

James Hunter wrote:
> 
> I'm trying to read in a template file -- basically, something that has a lot
> of text I'll be reusing -- and turn it into an actual file. ...

You might look at the Text::Template module on your local CPAN site.

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Mon, 21 Aug 2000 19:09:11 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Updating textfile problem...
Message-Id: <39A1E0C7.8D83E14F@ipac.caltech.edu>

musicfan wrote:
> 
> Sigh.  OK, here is the relevant code.  It outputs the  proper info
> when I use the debugger, but when I run it from the web page it
> doesn't actually execute the
> 
> print PEOPLE "$name|$password|$clickthrough\n";
> 
> line properly (e.g. the db file doesn't change at all, however when I
> run it through the debugger, the "testing purposes only" line reflects
> the proper record has been changed.)
> 
> I'm just trying to change field3 to a 1 if field1 is equal to the
> username passed by the browser!

[Code deleted]

Probably the only safe way to update a file with records (lines) which may be of
unequal length is to slurp in the whole file, modify the data, rewind the file
i/o pointer with 'seek', then write the whole thing out again, completely
overwriting the original file. Anything else gets really hairy except for
trivial cases. 

Also, try 'perldoc -q update' for other clues. Take note of the warnings at the
end.

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Mon, 21 Aug 2000 20:20:48 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Updating textfile problem...
Message-Id: <39A1F190.B9C6AD90@ipac.caltech.edu>

I forgot to mention that 'perldoc -q insert' also reveals a wealth of
information on exactly this topic.

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Tue, 22 Aug 2000 03:11:02 GMT
From: kcivey@cpcug.org (Keith Calvert Ivey)
Subject: Re: Updating textfile problem...
Message-Id: <39a5ee25.11718633@news.newsguy.com>

musicfan <musicfan@punitiveart.com> wrote:

>open(PEOPLE, "+<$datafile");

Change that to 

 open(PEOPLE, "+<$datafile") or die "Can't open $datafile: $!";

and you'll probably find that you've never opened the file.
Likely the current directory, the user the program is running
as, or the filename is not what you think.

Since it's a CGI program, you may want to put this near the
beginning so that you'll be able to see the error:

 use CGI::Carp 'fatalsToBrowser';

-- 
Keith C. Ivey <kcivey@cpcug.org>
Washington, DC


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

Date: Tue, 22 Aug 2000 03:17:25 +0200
From: Abe Timmerman <abe@ztreet.demon.nl>
Subject: Re: Variable vanishing?
Message-Id: <fdi3qsorchuaiterrc9c7gvsl0k6cm4lur@4ax.com>

On Mon, 21 Aug 2000 20:32:56 GMT, Steven Merritt
<smerr612@mailandnews.com> wrote:

> Here's semi-working code.
> 
> #! /usr/local/bin/perl -w
> use strict;
> 
> my $From_Date = 20000000000000;
> my $To_Date = 20000525135144;

I would declare those as strings:

	my $From_Date = '20000000000000';
	my $To_Date   = '20000525135144';

> my $Name = "";
> my $Oldest = "";
> my $Youngest = "";
> my $FlName = "";

These are not needed here, declare them in the scope where they are used

> my @fllist = `ls -1 /archive/??????????????-??????????????.log`;

See later for readdir

> my @Include = "";
> my @LogLines = "";

That propably doesn't do what you think it does.

	my @LogLines = ();
> 
> foreach $FlName (@fllist){
>   (undef, $Name) = split /\/archive\//, $FlName;
>   $Name =~ s/\.log//;
>   ($Oldest, $Youngest) = split /-/, $Name;
>   if ($Youngest < $From_Date){
>      next;
>      }
>      elsif ($Oldest > $To_Date){
>         next;
>         }
>   push @Include, $FlName;
>   }

Why are you processing the output of 'ls' rather that using perl buildin
opendir()/readdir()/closedir()
Something like:

	my $dir = '/archive';
	opendir ADIR, $dir or die "Can't opendir '$dir': $!\n";

	my @Include = map "$dir/$_" => sort
		grep {
			-f "$dir/$_" &&
			m!(\d{14})-(\d{14})\.log$! &&
			 $2 ge $From_Date && $1 le $To_Date
		} readdir ADIR;
	
	closedir ADIR;

Are you sure about that naming-convention, it seems odd. Swap $1 and $2
if the first 'timestamp' is the lesser.

> print @Include;
> 
> foreach $FlName (reverse @Include){
>   chomp $FlName;
>   open FH, '$FlName' or die "Couldn't open file $FlName $!\n";

The single quotes were already pointed out, but you might want to put
some delimiters around the file name in the diagnostic:

	open FH, $FlName or die "Couldn't open '$FlName': $!";

>      while (defined (<FH>)){
>        push @LogLines, $_;
>        }

If you're going to keep the contents in memory anyway, why not push the
whole file in one onto @LogLines and ditch the while?

	push @LogLines, <FH>;

I would close() the file handle.

>   }
> 
> print @LogLines;

-- 
Good luck,
Abe


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

Date: Tue, 22 Aug 2000 01:42:37 GMT
From: blavagna@my-deja.com
To: jand@ActiveState.com
Subject: WIN32:OLE and Excel: Approach to printing cell formulas ?
Message-Id: <8nslqa$u57$1@nnrp1.deja.com>

Can someone suggest an approach ? ? Thank you in advance :) :)
#####################
#  THE TASK:
#####################
  When *reading* cells from MS-Excel using WIN32:OLE , I would like to
*print* the FORMULAS, not the values that the Formulas take.
  I am using the the perlwin32-faq12 "How do I extract a series of
cells from Microsoft Excel? " example.
  I have included source code below.
  I am using Excel 97-sr2 on NT 4 sp5.

  (1) What I would like to be able to print out as a text file would be
a Mxn matrix of formulas like:
  [--------------------------------------------]
  [ =STDEV(B1:B3)  ;  =SUM(C1:C3) ; ...
  [ =IF(TYPE(F70)=1,F70*G70,"")   ; ...
  [ =CHISQR(B1:B3) ;
  [ ...

  (2) I'm unclear on the difference between the {'Value'} and {'Text'}
attribute.

  (3) Is there *any* method to recover the formulas.  Note, formulas
*do* appear, and are editable, within the Excel "Formula Edit Window" .

#####################
#  BUSINESS CASE:
#####################
  Your company has years of work invested in modeling things using MS
Excel spreadsheets.  You are tasked with exporting the *formulas* into
delimited text files so that the *formulas* can be easily re-coded in
Matlab, Perl, or some other real language.  The exported Excel formulas
will serve as a directly editable working prototype

#####################
#  EXAMPLE 1.
#  The most relevant line from perlwin32-faq12 :
#####################

   #-- As expected. This prints *values* like "2, 5, 88.2, etc"
   my $array = $Sheet->Range("A1:D6")->{'Value'};

#####################
#  EXAMPLE 2.
#  Another example from  http://blazonry.com/perl/xl_oleauto.html
#####################

   ## The following example is how to open an excel file, and read
values from cells in a worksheet.
   use OLE;
   $xlfile ="D:\\perl_read_test.xls";

   ##### OLE - Excel Connection
   # Create OLE object - Excel Application Pointer
   $xl_app = CreateObject OLE 'Excel.Application' || die $!;

   # Set Application Visibility
   # 0 = Not Visible
   # 1 = Visible
   $xl_app->{'Visible'} = 0;

   # Open Excel File
   $workbook = $xl_app->Workbooks->Open($xlfile);

   # Setup active worksheet
   $worksheet = $workbook->Worksheets(1);

   # Retrieve value from worksheet
   $cellA1 = $worksheet->Range("A1")->{'Value'};
   $cellB1 = $worksheet->Range("B1")->{'Value'};

   $cellA1Text = $worksheet->Range("A1")->{'Text'};
   $cellB1Text = $worksheet->Range("B1")->{'Text'};

   print "$cellA1\n$cellA1Text";


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 22 Aug 2000 03:58:24 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: WIN32:OLE and Excel: Approach to printing cell formulas ?
Message-Id: <39A1FA8F.C4DD475E@rochester.rr.com>

[warning:  mostly off-topic]
blavagna@my-deja.com wrote:
> 
> Can someone suggest an approach ? ? Thank you in advance :) :)

Sure.  Just use "Formula" instead of "Value" or "Text".  Like:

    $formula=$worksheet->Range("A1")->Formula;

for example.

 ...
>   (2) I'm unclear on the difference between the {'Value'} and {'Text'}
> attribute.

The "Value" property generates a Variant (number in Perl) containing the
value of the cell (or an array of arrays if there is more than one
cell).  The "Text" property returns the formatted value (the exact
characters you see in the spreadsheet cell) of a cell.  It doesn't work
on selections of more than one cell.  The "Formula" property returns the
formula text of a selection (scalar string if single cell; array of
arrays if more than one cell -- isn't Excel wonderful?).  Use Object
Brower in Excel to look up this crap.  And ask that stuff in an Excel
newsgroup, rather than a Perl newsgroup.
 ...
-- 
Bob Walton


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

Date: Tue, 22 Aug 2000 02:42:45 GMT
From: jason <elephant@squirrelgroup.com>
Subject: Re: would you recommend buying a book
Message-Id: <MPG.140c86168b7843d59896d5@localhost>

Jan Heidbrink <jan.heidbrink@gmx.net> wrote ..
>Hi!
>I'm planning to learn pearl. I'll mainly use it for CGI.
>Would you recommend to buy a book (if yes, where can I find an
>overview about some) or do you think, a free tutorial is enough? I'd
>prefer the last one as I don't have very much money. However, if you
>think that I should buy a good book, I'd do that.
>
>BTW: I'm already familiar with Pascal and C++.

  http://perl.oreilly.com/

-- 
  jason -- elephant@squirrelgroup.com --


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

Date: 21 Aug 2000 22:53:19 -0400
From: Jordan Katz <katz@underlevel.net>
Subject: Re: would you recommend buying a book
Message-Id: <m38ztq3t28.fsf@underlevel.underlevel.net>

jan.heidbrink@gmx.net (Jan Heidbrink) writes:

> Hi!
> I'm planning to learn pearl. I'll mainly use it for CGI.
                        ^^^^^ That's Perl.  Not like Pearl Jam.   
> Would you recommend to buy a book (if yes, where can I find an
> overview about some) or do you think, a free tutorial is enough? I'd
> prefer the last one as I don't have very much money. However, if you
> think that I should buy a good book, I'd do that.

You can learn everything from perldoc (run perldoc perldoc for more
information) but a book's much nicer.  You can find reviews of some
of the more well-known Perl books at:

  http://www.sysarch.com/cgi-bin/perl_books

For tutorials check out http://www.perl.com.

> BTW: I'm already familiar with Pascal and C++.

Then learning Perl will probably be easier (mostly because of the C++
part, not Pascal ;)).
-- 
Jordan Katz <katz@underlevel.net>


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

Date: Tue, 22 Aug 2000 03:25:01 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: would you recommend buying a book
Message-Id: <39A1F2BD.D2473477@rochester.rr.com>

Jan Heidbrink wrote:
 ...
> I'm planning to learn pearl. I'll mainly use it for CGI.
> Would you recommend to buy a book (if yes, where can I find an
> overview about some) or do you think, a free tutorial is enough? I'd
> prefer the last one as I don't have very much money. However, if you
> think that I should buy a good book, I'd do that.
> 
> BTW: I'm already familiar with Pascal and C++.

Why don't you pop over to www.amazon.com and type

   perl cgi

in their search box on the first page.  There you will find:

     Learning Perl (2nd Edition) -- Randal L. Schwartz, et al; Paperback 
     Programming Perl (3rd Edition) -- Larry Wall, et al; Paperback 
     CGI Programming with Perl -- Scott Guelich, et al; Paperback 

as the three items that pop up.  Those are certainly the three I would
recommend for you.  If you don't have much money, buy them anyway --
they'll pay for themselves quickly if you are planning on programming
Perl CGI for money.

Otherwise, read the docs that will be on your hard drive when you
install Perl.  They aren't (mostly) designed for learning, but
everything is there.
-- 
Bob Walton


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

Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 16 Sep 99)
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: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 4089
**************************************


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