[7427] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1052 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Sep 19 22:27:21 1997

Date: Fri, 19 Sep 97 19:00:21 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 19 Sep 1997     Volume: 8 Number: 1052

Today's topics:
     Re: '0': string or number? you make the call! <pittelli@ehsct7.envmed.rochester.edu>
     Re: .xs error values with a .pm method <sriram@weblogic.com>
     Re: Animated GIF problem in Perl (Tino)
     Re: bitwise xor of strings (Tad McClellan)
     Re: Calling a program from Perl script (Tad McClellan)
     chop/chomp, take 2 (Steve Lamb)
     Re: Confusion with chop/chomp <rootbeer@teleport.com>
     Re: Confusion with chop/chomp (Steve Lamb)
     Re: Convert To Currency (Tad McClellan)
     dates and other oddities of time <kolbe2@mail.klink.net>
     Re: Does Perl Have C's fflush function? (Tad McClellan)
     Re: Efficiency/New Perl Book: return @array vs \@array <sriram@weblogic.com>
     Re: Executing Shell commands in Perl (Tad McClellan)
     Re: Hash table reference in regex (Tad McClellan)
     Re: Help with file I/O problems. (Tad McClellan)
     Re: Newbie Question <tou@tou.com>
     Re: Where am I missing it <pittelli@ehsct7.envmed.rochester.edu>
     Digest Administrivia (Last modified: 8 Mar 97) (Perl-Users-Digest Admin)

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

Date: Fri, 19 Sep 1997 20:21:26 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
Subject: Re: '0': string or number? you make the call!
Message-Id: <874718095.21420@dejanews.com>

Empty strings AND any variable equal to 0 (or '0') returns false. That's
it. You can always set $num = int($string) to weed out the '00's.

In article <3422B94C.B606A76A@ixl.com>,
  Dan Boorstein <danboo@ixl.com> wrote:
>
> hello all,
>
> first off here is the code and results which confuse me:
>
> danboo> cat test.pl
> #!/usr/bin/perl -w
>
> $test0 = '0';
> $test00 = '00';
>
> $test0 && print "test0\n";
> $test00 && print "test00\n";
> danboo> ./test.pl
> test00
>
> now, here is what i thought would happen:
>
> $test0 would be assigned a string with the value '0'
> $test00 would be assigned a string with the value '00'
>
> $test0 would be defined as a non-empty string and print "test0\n"
> $test00 would be defined as a non-empty string and print "test00\n"
>
> as you can see, only "test00\n" was printed. so, is the string '0'
> a "failure/false" condition, or is it being evaluated as a numeric?
> i tried using the debugger to follow along but had little success.
>
> please help me understand the subtleties here.
>
> thanks,
>
> dan boorstein
> dboorstein@ixl.com

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: Fri, 19 Sep 1997 17:26:27 -0700
From: Sriram Srinivasan <sriram@weblogic.com>
To: Scott Grosch <grosch@ichips.intel.com>
Subject: Re: .xs error values with a .pm method
Message-Id: <34231833.96DA08BB@weblogic.com>

Scott Grosch wrote

> 
> I'm writing a perl module for LDAP, so I've defined an Ldap class, where I
> do '$thing = new Ldap' and I might have multiple of these in a program.  Most
> of the functions don't make it convenient to return both an error code and
> data, so I want to create an Ldap::errno type value.
> ...
>How do I attach it to the $thing I created?  Most
> .. 
> I'd hate to have to define a sub for each
> of those in the .pm file that called it, set an error, and returned, 
like:
> 
> sub func {
>         my $self = shift;
>         $self->{status} = ldap_func(shift);
> }
> 
> Is there a way from the .xs file to realize that I've been called from a method
> and then it can set the value directly?

Let's see if I understand this:
You have a set of LDAP functions in your .xs files that know nothing 
about Perl objects, then you have a .pm file that does a one-to-one 
mapping between the object method and the corresponding ldap function.

To capture the error status, I don't see why you would need
to write any *more* subroutines .. I also don't see any other
way of capturing the return status. 

Of course, if your naming convention is standard (that is, if
<func> always translates to ldap_func, then all you really 
need to write is an AUTOLOAD function to represent all calls
in one shot:

package Ldap;

sub AUTOLOAD {
    return if $AUTOLOAD =~ /DESTROY/;
    $obj = shift;
    # $AUTOLOAD contains Ldap::foo. Extract "foo" and make it ldap_foo
    ($func = $AUTOLOAD) =~ s/^.*::(.*)/ldap_$1/; 
    $obj->{status} = &$func (@_);
}

sub ldap_foo { # implemented in .xs 
    local $, = " ";
    print "ldap_foo called : @_";
}

sub new {
    bless {};
}
#-----------------------------
# testing Ldap.
$obj = Ldap->new();

$obj->foo(10, 20 ,30); # should call the subroutine ldap_foo

Hope my understanding of the problem is right.

- Sriram 
________________________________________________________________________
Principal Engineer      WebLogic, San Francisco        www.weblogic.com 
"Advanced Perl Programming" : http://www.ora.com/catalog/advperl/


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

Date: Sat, 20 Sep 1997 00:22:27 GMT
From: eberl@berlin.snafu.de (Tino)
Subject: Re: Animated GIF problem in Perl
Message-Id: <5vv52b$46d$1@unlisys.unlisys.net>

Mark Van Buren <vanburen@3dlinks.com> wrote:

>I've written a really simple script whose only job in life is to pass
>back an image from a query_string call.

>Example: In the HTML file

><IMG SRC="http://www.myserver.com/cgi-bin/image.pl?image.gif">

>image.pl

>#! /usr/local/bin/perl
>$basedir="http://www.myserver.com/images/";
>$file = (ENV{QUERY_STRING});
>print "Location: $basedir$file\n\n";

>This works and passes the image back, but if it's an animated gif, it
>only animates one cycle, then stops (NAV3/4) works fine under MSIE.
>Thank-you,
>Mark Van Buren

Hello Mark,

try following: (not tested!!!)

<IMG SRC="http://www.myserver.com/cgi-bin/image.pl?image.gif">

----

#! /usr/local/bin/perl

$basedir="http://www.myserver.com/images";
$file = (ENV{QUERY_STRING});

print "Content-Type: image/gif\n\n";
open (GRAPHIC, "$basedir/$file");
print <GRAPHIC>;
close (GRAPHIC);

---

Then 
1. Your browser known the file type which is returned (image/gif)
2 The file is fully printed out.

Hope I didn't mix anything and it helps you on...
let me know...

Cheer

Tino






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

Date: Fri, 19 Sep 1997 15:44:04 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: bitwise xor of strings
Message-Id: <k6ouv5.3r2.ln@localhost>

Ralph Stirling (stirra@wwc.edu) wrote:
: Bitwise exclusive-or on strings does not seem to work as

Strange.

This is the third post in the last couple of days about this...


: advertised in Prog Perl 2nd Ed. page 88.  Both AND and OR
                ^^^^^^^^^^^^^^^^^^^^^^^^^


Where it says:

   "...These operators work differently on numeric values than they do on 
    strings. (This is one of the few places where Perl cares about the 
    difference.)"


: work properly under Perl 5, and Perl 4 at least tries to
: get XOR (just leaves off the MSB when a zero), but XOR fails
: completely under Perl 5:

:         $b = "0101";
:         $c = "0011";


It is in quotes, so it must be a string...


:         $d = $b ^ $c; 


When given strings, xor operates on the ASCII values of the characters
in the string.

Does it work better if yo leave out those quotes?

Or, try a DejaNews search for 'bitwise' to find those other articles
I referred to.


: The only way I can figure to perform a bitwise XOR on bitstrings
: is to pack them, XOR, then unpack.  Anyone know of another
: solution, patch, or misunderstanding on my part?


0+$b;   # force perl to see that they are numeric...
0+$c;

$d = $b ^ $c;


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Fri, 19 Sep 1997 19:03:22 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Calling a program from Perl script
Message-Id: <as3vv5.m11.ln@localhost>

MetaLink (YDesfosses@videotron.ca) wrote:

: Yes, I would like to call a program that I did in C on Unix,
: In my Perl I want to catch the return value and do different
: thing depending on the value.


$return_value = system("your_C_prog arg1 arg2 ...") >> 8;

Have a look at the system() call in the perlfunc man page.

Ought to be pretty familiar to a C programmer  ;-)



: Does anyone can Help me?

: Please E-mail me

Please read the newsgroup where you asked the question.


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: 20 Sep 97 01:01:38 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: chop/chomp, take 2
Message-Id: <slrn6268t2.qaf.morpheus@death.calweb.com>

Tom,
    Here it is:

--- SNIP "bottest.log" ---
:GreydMiyu!morpheus@192.168.0.1 PRIVMSG #bottest :. version
--- SNIP "bottest.log" ---

    That is the line that the script tests.  First, the script that works.

--- SNIP "blah.work" ---
$channel = "#bottest";

open(BLAH,"bottest.log");
$line=<BLAH>;
close(BLAH);
($from, $type, $remainder) = split(/ /,$line,3);
$from =~ /^:(.*)!(.*)$/;
$from = $1;
$host = $2;
print("$from $host $type\n");
if ($type eq "PRIVMSG") # Standard messages
{
  ($dest, $remainder) = split(/ /,$remainder,2);
  print("inmsg: $from $type $dest $remainder\n");  # in case of errors
  if ($dest eq $channel)
  {
    print("-$from$remainder");
    if ($remainder =~ /:\. (.*)/)
    {
# *** Chop inside loop ***
      chop($chopme = $1);
      if ($chopme eq "version")
      {
        print("version\n");
      }
    }
  }
}
--- SNIP "blah.work" ---

Output:

GreydMiyu morpheus@192.168.0.1 PRIVMSG
inmsg: GreydMiyu PRIVMSG #bottest :. version

-GreydMiyu:. version
version

   
    Now two scripts that fail.

--- SNIP "blah.fail1" ---
$channel = "#bottest";

open(BLAH,"bottest.log");
$line=<BLAH>;
close(BLAH);
($from, $type, $remainder) = split(/ /,$line,3);
$from =~ /^:(.*)!(.*)$/;
$from = $1;
$host = $2;
print("$from $host $type\n");
# *** chop outside loop
chop($remainder); 
if ($type eq "PRIVMSG") # Standard messages
{
  ($dest, $remainder) = split(/ /,$remainder,2);
  print("inmsg: $from $type $dest $remainder\n");  # in case of errors
  if ($dest eq $channel)
  {
    print("-$from$remainder");
    if ($remainder =~ /:\. (.*)/)
    {
      if ($1 eq "version")
      {
        print("version\n");
      }
    }
  }
}
--- SNIP "blah.fail1" ---

Output:
GreydMiyu morpheus@192.168.0.1 PRIVMSG
inmsg: GreydMiyu PRIVMSG #bottest :. version

--- SNIP "blah.fail2" ---
$channel = "#bottest";

open(BLAH,"bottest.log");
$line=<BLAH>;
close(BLAH);
($from, $type, $remainder) = split(/ /,$line,3);
$from =~ /^:(.*)!(.*)$/;
$from = $1;
$host = $2;
print("$from $host $type\n");
if ($type eq "PRIVMSG") # Standard messages
{
  ($dest, $remainder) = split(/ /,$remainder,2);
  print("inmsg: $from $type $dest $remainder\n");  # in case of errors
*** chop right before where it would be in the inner loop
  chop($remainder);
  if ($dest eq $channel)
  {
    print("-$from$remainder");
    if ($remainder =~ /:\. (.*)/)
    {
      if ($1 eq "version")
      {
        print("version\n");
      }
    }
  }
}
--- SNIP ---

Output:
GreydMiyu morpheus@192.168.0.1 PRIVMSG
inmsg: GreydMiyu PRIVMSG #bottest :. version


    Now, let's look this over, ok?  In script 1 it works, everything is
printed down to the version.  In script 2, the output is:

GreydMiyu morpheus@192.168.0.1 PRIVMSG
inmsg: GreydMiyu PRIVMSG #bottest :. version

   It gets inside the PRIVMSG check because we have the inmsg line printed. 
It does not, however, get into the first inner loop because there is no line
starting with a -.

    In script number three, the same thing occurs.  We get into the inmsg
line, but no further.

    Now, can you see why I say that $dest is not, or is it EVER being
modified?  Now, do you see why, although I am going to do the chop/chomp on
the innermost loop (which is now a subroutine) I am still miffed as to why
it will not get past a variable which should not be modified if placed
before that check?  It is not even getting to the check for "version", we
know this, there is no "-" line. 

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
CC: from news not wanted or appreciated| skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: Fri, 19 Sep 1997 17:08:55 -0700
From: Tom Phoenix <rootbeer@teleport.com>
To: Steve Lamb <morpheus@calweb.com>
Subject: Re: Confusion with chop/chomp
Message-Id: <Pine.GSO.3.96.970919170148.21537U-100000@julie.teleport.com>

On 19 Sep 1997, Steve Lamb wrote:

> $remainder = "#bottest :blahblahblah\n"

Missing semicolon on previous line. :-)

> chomp($remainder);
> ($dest, $remainder) = split(/ /,$remainder,2);
> 
>     OK?  $dest should now be "#bottest" and $remainder should be
> ":blahblahblah".  However, that data fails the if ($channel eq $dest)
> test. 

What's in $channel? If it's '#bottest', then the test should succeed. It
does on my machine.

> Now, if I move the chomp after the check, which means that $dest is still
> "#bottest" and $remainder is ":blahblahblah\n" it works.  It is only when I
> chomp/chop before that check that it fails.

Are you saying that you chomp _after_ comparing $channel to $dest? If
$channel has a trailing newline, then you should probably chomp it, as
well.

>     I'll most likely place the chomps as far inside the loops as I can
> to save some time there. 

Doing any operation once (out of a loop) is faster than doing it many
times (inside of a loop). 

> But the whole idea that it works in one location and
> not the other has me quite miffed.

It's doing what you ask of it! :-)

>     So far I've gotten three responses and none have explained why
> moving that one line causes a portion of the string that isn't even near
> the newline to fail. 

If you can write a small stand-alone script (not just a section snipped
out of a script) which shows this behavior, I'll be glad to help you see
why it's doing what it's doing. But I can't use the examples you've
posted to get Perl to do anything that surprises me. :-)

-- 
Tom Phoenix           http://www.teleport.com/~rootbeer/
rootbeer@teleport.com  PGP   Skribu al mi per Esperanto!
Randal Schwartz Case:  http://www.rahul.net/jeffrey/ovs/
              Ask me about Perl trainings!



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

Date: 20 Sep 97 00:35:54 GMT
From: morpheus@calweb.com (Steve Lamb)
Subject: Re: Confusion with chop/chomp
Message-Id: <slrn6267cp.qaf.morpheus@death.calweb.com>

On Fri, 19 Sep 1997 17:08:55 -0700, Tom Phoenix <rootbeer@teleport.com> wrote:
>Missing semicolon on previous line. :-)

    Example off the top of my head.

>> chomp($remainder);
>> ($dest, $remainder) = split(/ /,$remainder,2);
>> 
>>     OK?  $dest should now be "#bottest" and $remainder should be
>> ":blahblahblah".  However, that data fails the if ($channel eq $dest)
>> test. 

>What's in $channel? If it's '#bottest', then the test should succeed. It
>does on my machine.

    Yes, that is the channel.  

>> Now, if I move the chomp after the check, which means that $dest is still
>> "#bottest" and $remainder is ":blahblahblah\n" it works.  It is only when I
>> chomp/chop before that check that it fails.

>Are you saying that you chomp _after_ comparing $channel to $dest? If
>$channel has a trailing newline, then you should probably chomp it, as
>well.

    You are missing the entire point.  Here is the point.  At *NO* time,
whatsoever, does chomp come close to $dest!!!  Here is a line of input which
goes into $line.

:GreydMiyu!morpheus@192.168.0.1 PRIVMSG #bottest :. version^M\n

    First I do this:
($from, $type, $remainder) = split(/ /,$line,3);

    So now I should have it broken up like this:

:GreydMiyu!morpheus@192.168.0.1 PRIVMSG #bottest :. version^M\n
|          $from              | |$type| | $remainder          |

    I do some parsing on $from to seperate the host from the username.  Then
I check $type to see if it is PRIVMSG.  If so, I do another split:

($dest $remainder) = split(/ /,$remainder,2);

    Now it should look like:

#bottest :. version^M\n
|$dest | | $remainder |

    If $dest eq $channel then I run $remainder through a filter to extract
everything after the ". ".  So then $1 becomes, "version^M\n".  That is when I
finally chomp to get it to match my commands.  And that sequence works.

    However, if I chomp *ANYWHERE* before the second split which seperates
out $dest fromo $remainder $dest does not match $channel.

    Now, Tom, tell me *WHY* does chomp (or chop, right now I'm using chop)
have an effect on what goes into $dest when what goes into $dest is *NEVER*
at the end of the string?  I chomp/chop $remainder which *ALWAYS*, if it
gets that far, has something after the channel name.  Always.  Even if it is
just a ":^M\n".

    This is getting frustrating when you are sitting there saying that
chop/chomp is modifying $dest when it flat out is not.  There is no newline
there.  There is no space.  Unless split is doing something I am unaware of
$dest should remain constant no matter where I chop/chomp $remainder.  

>Doing any operation once (out of a loop) is faster than doing it many
>times (inside of a loop). 

for ($x=0;$x<10;$x++)
{
  print("Bah!\n");
  if ($x == 5)
  {
    print("Boo!\n");
  }
}

output:
Bah!
Bah!
Bah!
Bah!
Bah!
Boo!
Bah!
Bah!
Bah!
Bah!
Bah!

    Now imagine the Bah! being if I chop/chomp each on each string every
time and the Boo! is when I do it only when I am checking to see if a
a command is sent to the bot.  That is the difference between doing it once
on the outside of the loop and doing it once on the inside of the loop.


>It's doing what you ask of it! :-)

    No.  At no time should it ever remove anything from $dest.  This should
be clear in the above example.  I cannot think if any other way to make it
clearer.

>If you can write a small stand-alone script (not just a section snipped
>out of a script) which shows this behavior, I'll be glad to help you see
>why it's doing what it's doing. But I can't use the examples you've
>posted to get Perl to do anything that surprises me. :-)

    Then you are misunderstanding me because you keep insisting that perl is
modifying $dest.  Well, if it is modifying $dest, please let me know why. 
Because from this viewpoint it should not be.  And if that doesn't surprise
you, I dunno what will.

-- 
             Steve C. Lamb             | Opinions expressed by me are not my
    http://www.calweb.com/~morpheus    | employer's.  They hired me for my
CC: from news not wanted or appreciated| skills and labor, not my opinions!
---------------------------------------+-------------------------------------


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

Date: Fri, 19 Sep 1997 20:21:06 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Convert To Currency
Message-Id: <2e8vv5.bc1.ln@localhost>

Jim Durbin (nada@zilch.com) wrote:
: I need to be able to display a number as currency with commas and cents...
: $##,###.##
: I'm relatively new to Perl and I can't seem to find a reference to this
: format anywhere.
: The closest I can come is this:

: format STDOUT =
: $@#####.##
: $cashvalue
: ..

: Works but doesn't place commas in the number.  I could write my own code
: that parses the number an inserts the commas where needed but there must be
: a module or code sniplet out there that does this already.


Perl FAQ, part 5:

   "How can I output my numbers with commas added?"




You aren't working with money as floating point numbers are you?

You can easily lose some money that way.

You should work with integer cents until the very end, and then
convert to floating point only for the final output...


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Fri, 19 Sep 1997 21:41:10 -0700
From: Nate Riggs <kolbe2@mail.klink.net>
Subject: dates and other oddities of time
Message-Id: <342353E4.FF8F15DA@mail.klink.net>

Sorry, I'm a newbie at perl.  Is there a function to retrieve the date?

Thanks in advance

Nate



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

Date: Fri, 19 Sep 1997 19:34:22 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Does Perl Have C's fflush function?
Message-Id: <em5vv5.g71.ln@localhost>

Jonathan Nichols (Jonathan.O.Nichols@ast.lmco.com) wrote:
: The subject says it all.  Can I flush an output buffer like I can in C
: with the fflush function?


Have you grepped for 'fflush' in the free documentation that is
included with the perl distribution?


I find it under 'POSIX' in perltoc (5.004)...


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Fri, 19 Sep 1997 18:10:41 -0700
From: Sriram Srinivasan <sriram@weblogic.com>
Subject: Re: Efficiency/New Perl Book: return @array vs \@array
Message-Id: <34232291.A718DC6B@weblogic.com>

Harold Todd Chapman wrote:
<< 

 use Benchmark;
 timethis(1000000, "iso_xy()");

  sub iso_xy {
        return @points;
        #return \@points; #if I uncomment this line and comment above
                          #the benchmark take 50% longer!
 }
>>


All you are doing in this benchmark is to return the same array
over and over again, without using it. Perl notices the fact
that you are not using the return value, so it doesn't do 
anything internally. 

If you return \@points, Perl creates a reference to that array,
and notices that you don't do anything with that scalar, so it
junks it .. but meanwhile it incurs the cost of creating that
scalar.

When benchmarking make sure you do something with the return value.
In a real system, if you said
  @foo = iso_xy(), 
you incur the cost of an array copy,
whereas if you said,
  $foo = iso_xy(), you only incur the cost of a scalar copy.

- Sriram 

________________________________________________________________________
Principal Engineer      WebLogic, San Francisco        www.weblogic.com 
"Advanced Perl Programming" : http://www.ora.com/catalog/advperl/


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

Date: Fri, 19 Sep 1997 19:59:16 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Executing Shell commands in Perl
Message-Id: <457vv5.b91.ln@localhost>

wchrist@flagmail.wr.usgs.gov wrote:
: I have been trying to execute the following commands in Perl with no
: success.  Can anyone help?

: open HANDLE, "| taetm" or die "Can't run taetm: $!\n";
                                 ^^^^^^^^^^^^^^^

That is a misleading diagnostic message.

Even if you have no 'taetm' command on your system, or if taetm is
not executable, or there is any other problem (other than the fork
failing), that message will not be printed...

Have a look at the below Frequently Asked Question (part 8):

   "Why doesn't open() return an error when a pipe open fails?"


: print HANDLE <<DONE;
: quadplot FROMLIST=list.txt TITLE=test PROJ=SIMP LAT=(10.0,12.0)
: LON=(130,170) KM=1.0 CLAT=11.0 CLON=150.o
: exit
: DONE

: close(HANDLE);

That code is basically the same as:

system "echo 'quadplot FROMLIST=list.txt TITLE=test PROJ=SIMP LAT=(10.0,12.0)
LON=(130,170) KM=1.0 CLAT=11.0 CLON=150.o
exit' | taetm";

(with those newlines in it too)

Would that be expected to work with taetm?


: taetm is a software package, and quadplot is an application that runs
: under taetm.  

I don't grok 'runs under'.

You are putting stuff onto the STDIN of taetm. Is that what you are
supposed to do to get it to run quadplot?


: Starting with FROMLIST, each item in capitals is a parameter
: for quadplot, with the appropriate value listed, and all parameters are
: supposed to be on the same line.  The exit call terminates the taetm
                 ^^^^^^^^^^^^^^^^

But you are giving them to taetm on two lines there.

Is that a problem?

Have you tried it with all the parameters on one line?

   $cmd = 'quadplot FROMLIST=list.txt TITLE=test PROJ=SIMP LAT=(10.0,12.0) '
        . 'LON=(130,170) KM=1.0 CLAT=11.0 CLON=150.o'
        . "\nexit\n";

   print HANDLE $cmd;    # or system("echo '$cmd' | taetm")


Or does the 'supposed to' part mean that they are on one line in your
real code, and that you just word wrapped them for inclusion in
your post?


: session.  I was able to do this same thing successfully in the past with a
: different application for taetm.  I have put arbitrary print statements
: after the open() call, and they appear in the output.  However, when I run
: the ps -u command, no taetm process is being started.  Any suggestions on
: what I am doing wrong?


I dunno, because I'm not sure how taetm is supposed to be used...

Maybe try it with a system() call instead, and inspect the return value.


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Fri, 19 Sep 1997 20:04:12 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Hash table reference in regex
Message-Id: <ce7vv5.b91.ln@localhost>

Bruno Pagis (bruno_pagis@aur.alcatel.com) wrote:
: Usage of hash table reference in a regular expression:

: %map = (
:         "UID" => "A",
:          "PID" => "B");

: $msg='<UID>:<PID>';
: $msg =~ s/<(\w+)>/$map{\1}/g;
: print "$msg\n";

: I expect A:B but I've got :


Put a -w switch on your shebang line and try it again.

Then follow its suggestion.

It will work fine then.

You should have been using -w all along anyway...



#!/usr/bin/perl -w


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Fri, 19 Sep 1997 18:52:22 -0500
From: tadmc@flash.net (Tad McClellan)
Subject: Re: Help with file I/O problems.
Message-Id: <m73vv5.6v.ln@localhost>

Icepick (icepick@NOSPAMpclink.com) wrote:
: Okay, quick and dirty background.  I'm new to perl, and working on
: various projects just to learn.  More or less the jump in first then
: learn to swim method of self teaching.

: I'm currently working on a program that reads in a file called "text"
: and stores it in an @ array, one character per element, then XOR's
: each character with a value, then writes it all out to another
: file "output"  It's the begining of a simple crypto script I'm 
: messing with.

: My problem is that the output file is longer than the input file, and
: I can't figure it out.  Also, when the output file is renamed to "text"
  ^^^^^^^^^^^^^^^^^^^^^

You have a few 'off by one' errors in there...


: and run through the script again, it should yield back the orginal
: "text" file.  Alas, it doesn't.  It does, however, work on the first
: portion of the file.  Strange.

: Here's the relevant portions of the script (just cut and paste, should
: work for you) and the "text" file.  Any suggestions?

: ----------begin script-------

: #/usr/bin/perl -w
  ^^
  ^^

Excellent!

Oh that everyone who is learning perl would use the -w switch...

(you're missing a ! there though)


: # get the data
: print "Getting the text from \"text\"\n";
: open (INP, "text") || die "can't open \"text\""; # open the file (nicely)

: $i=0;
: while (defined ($p[$i]=<INP>)) {
:   $i++;
:  }

You don't really need to count them as they go into the array.

You can just use @p in a scalar context to get the number of elements
in @p.


: $lines=$i;              # number of lines of data
: $len=0;
: for ($i=0;$i<=$lines;$i++) {
              ^^
              ^^ should be just < ('cause you are starting the count at zero)

:  for ($j=0;$j<=length($p[$i]);$j++) {
               ^^
               ^^
:    $plain[$len]=ord(substr($p[$i],$j,1));    # convert to ascii
:    $len++;
:  }
: }

: close (INP) || die "can't close \"text\"";       # and close it (nicely)
: print "$lines lines    $len  chars\n";

: # do the encryption
: print "Encrypting...\n";

: $jj=0;
: while ($jj<$len) {     # while the number of bytes done is <=
            ^
            ^ you did it right here though  ;-)


:                         # the length of the plaintext
: $cipher[$jj]=$plain[$jj]^$jj ;   
: $jj++;
: }

: # all done, now write it to output
: print "Outputing to \"output\"\n";
: print $len;

: open (OUTP, ">output") || die "can't open \"output\"";
: for ($i=0;$i<=$len;$i++) {
              ^^
              ^^ yet again

:   print OUTP chr($cipher[$i]);
: }

: close (OUTP) || die "can't close \"output\"";

: ----------- end script  -----------


: ---------- begin test "text" file ---------

: another
:  line in
:  the works this is going to be
:   a really really really really long line
:    with no cairage s returns or line breaks or
:     line feeds or any of

: 1234567890 !@#$%%^^&&*(())

:      that other silly nonsense
: that messes things up.
:       
: ----------------- end "text" file --------------



That seemed like such a fun project, that I rewrote it in more 
idiomatic perl. Produces the same output as yours (after fixing
your loop limits):


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

# I don't like to backwack. You can use an alternate quoting mechanism.
# I used double quotes below.
#
# But q() (single quotes) would be better, since you don't have
# anything in there to interpolate anyway...

open (INP, "text") || die qq(can't open "text"); # qq is for double quotes

while (<INP>) {                # get a line.
   foreach $ch (split(//)) {   # splitting on the null pattern returns
      push(@plain, ord($ch));  # each individual character, which are
   }                           # then pushed into @plain
}
close(INP);  # not required, but I like to be explicit, plus it helps me
             # when I come back to it in a few weeks/months because I can
             # easily see that I am finished with the file at this point
             # in the program


# do the encryption
print "Encrypting...\n";

for ($jj=0; $jj<@plain; $jj++) {
   push(@cipher, ($plain[$jj] ^ $jj));
}

open (OUTP, ">output") || die q!can't open "output"!; # single quotes this time
                                                      # different delimiter too
foreach (@cipher) {
   print OUTP chr($_);
}
close(OUTP);
--------------------------


--
    Tad McClellan                          SGML Consulting
    tadmc@flash.net                        Perl programming
    Fort Worth, Texas


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

Date: Fri, 19 Sep 1997 17:01:39 -0700
From: Joel Shellman <tou@tou.com>
Subject: Re: Newbie Question
Message-Id: <34231263.F20C86D0@tou.com>

Jeremy D. Zawodny wrote:
> 
> [cc'd automagically to original author]
> 
> On Wed, 17 Sep 1997 07:02:58 -0500, fischers@execpc.com wrote:
> 
> >I am posting a form to a cgi perl script.  I want to access a hidden
> >field in the form.  How do I access the variable?
> 
> Use the CGI.pm module from CPAN, and you'll be able to access hidden
> variable in the same way that you will access non-hidden ones. :-)
> 
> Jeremy

I have been using cgi-lib.pl.  Can someone please tell me if hidden variables
are EVER treated different than non-hidden ones (on the server side)?  I always
thought they were only hidden in the browser and that had nothing to do with the
server.

Thank you,

Joel
Joel

-- 
TaoTree Research and Development
Web Development/Design, Virtual Servers, hosting, Perl/CGI programming
http://www.tou.com/rd/

Revolutionary new clicks-based Banner Exchange Guarantees you traffic
http://www.tou.com/ite/


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

Date: Fri, 19 Sep 1997 20:11:40 -0600
From: Randal Pittelli <pittelli@ehsct7.envmed.rochester.edu>
To: gatcat@gatman.SPAMBUFFER.com
Subject: Re: Where am I missing it
Message-Id: <874717638.20884@dejanews.com>

1) No need to remove the shebang (prob should leave it there, to help you
in writing portable code). It's read as a comment on NT.

2) sendmail uses its own syntax, which is different than (Unix) mail.exe
syntax, which is also different than SMTP commands. Undoubtedly any NT
mail program will have its own, unique, syntax.

3) If comments.exe is in fact in the CGI directory, then it's already a
form processor!!! Therefore point your form to /cgi-bin/comments.exe (if
that is in fact the name of the CGI dir). You may need to also find out
from your ISP what the control variable names are, but if the program was
written *well* you should be able to use your old ones (e.g. recipient,
email, name, subject, message or body, redirect...)

4) An alternative to all this of course is to use a mailer that writes to
an SMTP server directly! Try:
http://128.151.21.16/wwwrlp/perlcal/support.htm for a simple (free) one
that does this (can easily be modified to do more).


-Randy

In article <3421e5f1.16115395@news.gate.net>,
  gatcat@gatman.SPAMBUFFER.com wrote:
>
> Using perl script -- works fine in Unix.
>
> Have moved same over to NT and renamed script with .plx extension and
> removed shbang line.
>
> Original  variable for send mail was:
> $mailprog = '/usr/lib/sendmail';
>
> ISP tells me that their mail program is COMMENTS.EXE and located in
> cgi-bin directory.
>
> My interpretation to correct this was as follows:
>
> $mailprog = '/cgi-bin/COMMENTS.EXE';
>
> Where am I missing it??
>
> Prompt reply a big help - Thanks
>
> John Gattuso
> gatman@gate.nospam.net

-------------------==== Posted via Deja News ====-----------------------
      http://www.dejanews.com/     Search, Read, Post to Usenet


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

Date: 8 Mar 97 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 8 Mar 97)
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.  

To submit articles to comp.lang.perl.misc (and this Digest), send your
article to perl-users@ruby.oce.orst.edu.

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.

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

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

For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V8 Issue 1052
**************************************

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