[16857] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4269 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Sep 9 00:05:26 2000

Date: Fri, 8 Sep 2000 21:05:08 -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: <968472307-v9-i4269@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 8 Sep 2000     Volume: 9 Number: 4269

Today's topics:
    Re: Changing ALL leading blanks to zero <tina@streetmail.com>
    Re: Help with Expect Perl Script <econcilio@goamerica.net>
    Re: How to find unused variables? <sallan@nwlink.com>
    Re: How to find unused variables? (Gwyn Judd)
    Re: Is this a bug or a feature? elliotfinley@my-deja.com
    Re: Is this a bug or a feature? elliotfinley@my-deja.com
    Re: Is this a bug or a feature? elliotfinley@my-deja.com
    Re: New Perl Tutorial - www.perltutor.com (Gwyn Judd)
    Re: New Perl Tutorial - www.perltutor.com (Gwyn Judd)
    Re: Perl-native code for finding mail exchanger: nslook <care227@attglobal.net>
        Perl-native code for finding mail exchanger: nslookup - bryl@my-deja.com
    Re: Regular Expressions <jeffp@crusoe.net>
    Re: using "|" as plain text in scripts (perl win) <jjohn@cs.umb.edu>
    Re: Variable not accepting value <jjohn@cs.umb.edu>
    Re: Variable not accepting value <tina@streetmail.com>
    Re: website (Tony L. Svanstrom)
    Re: website (Abigail)
    Re: what is the best way to get the lastest line from a <jjohn@cs.umb.edu>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: 9 Sep 2000 02:30:09 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Changing ALL leading blanks to zero
Message-Id: <8pc7bh$cdg2l$1@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc Mark McCarthy <markmccarthy1@home.com> wrote:

> "Tom Christiansen" <tchrist@perl.com>

>> while (/\G,?(\d+)/g) {
>>     print "Found number $1\n";
>> }

> If I try this example without \G, I get the same answer!

> (I chose $_="3,4,5,9,120"; as was suggested )

> So whats the benefit of  \G here?

the original question wan was how to transform leading whitespaces
to "0"s. mark the "leading".

without the \G you would replace *all*
whitespaces.

of course, with the example string
"3,4,5,9,120" you will get the same result as
without \G with the above code. but
try it out with
"3,4,5,9,120 this number 42 should not appear"

tina

-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Fri, 08 Sep 2000 23:10:00 -0400
From: Edward Concilio <econcilio@goamerica.net>
Subject: Re: Help with Expect Perl Script
Message-Id: <i6ajrssb1h3oaaf4juon58o5lqic4s2av6@4ax.com>

On Thu, 7 Sep 2000 04:21:32 GMT, ced@bcstec.ca.boeing.com (Charles
DeRykus) wrote:

>In article <u99drs8a6bu6pctah80damaamiocd502hr@4ax.com>,
>Thomas George  <ygguh@aol.com> wrote:
>>Below is a snippet of my script which doesn't work correctly, or should I say,
>>it doesn't return the information I require. What the script does is connect up
>>to a UNIX box and runs a perl script which checks a userid against a reservation
>>file, similar to struct passwd. 
>>
>>If the userid is not in the reservation file, it is then entered and I will
>>receive a return message of: "0, USERID reserved".
>>
>>If the userid is already in the reservation file, I will then receive a return
>>message of: "1, USERID exists".
>>
>>And, if both the above two conditions fail, or if the userid is not within a
>>predefined format, I will then receive a return message of: "#, Error <REASON>"
>>where "#" is a number between 2 and 20 and "REASON" is a test error message.
>>
>>As you will see, I have tried several ways of capturing the return code from my
>>expect command with no positive results.
>>
>>Any help would be appreciated.
>>
>>#!/usr/local/bin/perl
>>
>>use Expect;     # This is a module, needs supporting modules too.
>>
>>$Expect::Log_Stdout=1;
>>$Expect::Debug=3;
>>$Expect::Exp_Internal=1;
>>
>># Basic stuff to setup session.
>>$cmd = "/usr/bin/telnet" ;
>>$host = "smtp.server.net." ;
>>$login = "george" ;
>>$passwd = "abc123" ;
>>
>># Our arguments.
>>$NAME = $ARGV[0] ;
>>
>># Count the command line args, if there's not enough, give usage and exit.
>>$count = @ARGV ;
>>if ($count < 1) {
>>    print "Usage: usercheck.pl NAME\n" ;
>>    exit 0 ;
>>    } else { # Connect to the remote host.
>>         $expect = Expect->spawn("$cmd $host") || die "Can't connect to $host" ;
>>          $expect->log_stdout(0) ; # Log to STDOUT.
>>          unless ($expect->expect(5, "login:")) {     # Wait for login prompt.
>>                print "Error: host timed out waiting for $host\r"
>>          }
>>          print $expect "$login\r" ; # Send our username.
>>          unless ($expect->expect(5, "Password:")) {    # Wait for Password.
>>                print "Error: login timed out waiting for $host\r"
>>          }
>>        print $expect "$passwd\r" ;  # Send our passwd.
>>        unless ($expect->expect(5, "\$")) {
>>                print "Error: passwd timed out waiting for $host\r"
>>        }
>>
>>        #($code,$message)=$expect->expect(5,"./usercheck $NAME\n") ;
>>         print $expect "./usercheck $NAME\n" ;
>>         ($code,$message)=$expect->expect(5,'-re','[0-9]*');
>>        
>>        $status = $code;
>>        
>>        if ($status == 0) {
>>                print "Okay\r";
>>        } else {
>>                print "Not $message\r";
>>        }
>>
>>          print $expect->exp_match();
>>          # $expect->soft_close() ;
>>      }
>>exit 0 ;
>
>
>Not to dissuade if you've got a compelling reason for
>Expect.pm, but Net::Telnet would be easier here
>I believe. Here's a rough, unwarrantied cut at it: 
>
> 
>#!/usr/local/bin/perl -w
>
>use Net::Telnet;
>use strict;
>
>my $NAME = $ARGV[0] or die "usuage: ....";
>my $host = "smtp.server.net";
>
>my $telnet = new Net::Telnet (Timeout => 60,
>                              Prompt => "/$host\$ $/",
>                              #Dump_log =>*STDOUT, 
>                             );
>
>$telnet->open($host);
>$telnet->login($acct, $password);
>my ($code, $msg) = $telnet->cmd("./usercheck $NAME");
>$telnet->close;
>__END__
>
>
>
>hth,

>Not to dissuade if you've got a compelling reason for
>Expect.pm, but Net::Telnet would be easier here
>I believe. Here's a rough, unwarrantied cut at it: 

My only compelling force is to provide a script that works everytime.
And which doesn't require my constant attention.
Anyway below is the final script. Thanks for the help!

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

use Net::Telnet ();
# use strict;

my $NAME = $ARGV[0] || die "usage: ./usercheck.pl username\n";
my $host = "smtp.server.net" ;
my $username = "johndoe";
my $passwd = "abc123" ;

$t = new Net::Telnet (Timeout => 10,
        # Dump_log =>*STDOUT,
        # there is a space between the backslash and "doe"
        Prompt => '/johndoe \$ $/');

$t->open($host);
$t->login($username, $passwd);

@msg = $t->cmd("./usercheck $NAME");
$t->close;
print "message @msg";
Edward A. Concilio
IS Manager, UNIX Admin
The New York Academy Of Medicine
1216 5th Ave.
New York City, NY  10029
econcilio@nyam.org
http://www.nyam.org
(212) 822-7308


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

Date: 08 Sep 2000 20:05:27 -0700
From: Steve Allan <sallan@nwlink.com>
Subject: Re: How to find unused variables?
Message-Id: <u1yyucljc.fsf@nwlink.com>

"Dr. Peter Dintelmann" <Peter.Dintelmann@dresdner-bank.com> writes:

>    Hi,
>
>Thomas Åhlen schrieb in Nachricht
><_HPt5.252$pz5.129366@news.bahnhof.se>...
>
>>I always use "use strict" and always declare my variables at the top of
>the
>>script code.
>
>    [snip]
>
>>I want to get warning when variables are declared but not used so i can
>>eliminate them.
>>How can i get that info?
>
>    you want to get warnings: use the '-w' switch
>
>        #!/usr/bin/perl -w
>        use strict;
>        $a = 'bla';
>
>   When running you get a message
>
>    Name "main::a" used only once: possible
>    typo at ...
>

But this doesn't produce warnings for variables declared local with
my(). BTW - how did you slip that $a = 'bla' past stict? It doesn't 
compile for me.  Try this example -

#!/usr/bin/perl -w
use strict;
my $local = 'local';
no strict 'vars';
$global = 'global';
exit 0;

$> perl unused.pl
Name "main::global" used only once: possible typo at unused.pl line 9.

It reports unused global, but not local.  So I'm left with the same
question as the OP.

-- 
-- Steve __




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

Date: Sat, 09 Sep 2000 04:00:37 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: How to find unused variables?
Message-Id: <slrn8rjdf2.d3q.tjla@thislove.dyndns.org>

I was shocked! How could Steve Allan <sallan@nwlink.com>
say such a terrible thing:

>But this doesn't produce warnings for variables declared local with
>my(). BTW - how did you slip that $a = 'bla' past stict? It doesn't 
>compile for me.  Try this example -

$a is special. See "perldoc -f sort"

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
coitus interruptus, n:
	A jerky movement following the words (by either sex partner)
	"I want to have your child."


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

Date: Sat, 09 Sep 2000 01:17:21 GMT
From: elliotfinley@my-deja.com
Subject: Re: Is this a bug or a feature?
Message-Id: <8pc32i$6kb$1@nnrp1.deja.com>

In article <8p7adu$9uk$1@provolone.cs.utexas.edu>,
  logan@cs.utexas.edu (Logan Shaw) wrote:
> In article <8p785o$gj1$1@nnrp1.deja.com>,  <elliotfinley@my-deja.com>
wrote:
> >#!/usr/bin/perl -w
> >
> >use strict;
> >
> >main();
> >exit;
> >
> >sub main {
> >    my $v = 10;
> >
> >    while($v > 0) {
> >        {
> >            if ($v > 5) {
> >                print "One\n";
> >                $v--;
> >                next;
> >            }
> >        }
> >        {
> >            if ($v > 0) {
> >                print "Two\n";
> >                $v--;
> >                next;
> >            }
> >        }
> >        last;
> >    }
> >}
> >
> >The output from this program is:
> >One
> >Two
> >
> >I expected it to be:
> >One
> >One
> >One
> >One
> >One
> >Two
> >Two
> >Two
> >Two
> >Two
>
> From "perldoc perlsyn":
>
>      A BLOCK by itself (labeled or not) is semantically
>      equivalent to a loop that executes once.  Thus you can use
>      any of the loop control statements in it to leave or restart
>      the block.
>
> Thus, your "next"s just finish the blocks immediately outside of the
if
> statements, rather than finishing the block for the while loop.
>
> So, the first time through the loop, the "next" jumps to just outside
> the first closing brace in the same column as the "e" of "while".  The
> second "next" jumps to just outside the second such closing brace, and
> that takes you to "last", which ends the loop.
>
>   - Logan
>

Thank you Logan, this explains it perfectly.


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


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

Date: Sat, 09 Sep 2000 01:21:53 GMT
From: elliotfinley@my-deja.com
Subject: Re: Is this a bug or a feature?
Message-Id: <8pc3b0$6ul$1@nnrp1.deja.com>

In article <YMFt5.23$8S.3791@vic.nntp.telstra.net>,
  "Wyzelli" <wyzelli@yahoo.com> wrote:
> <elliotfinley@my-deja.com> wrote in message
> news:8p785o$gj1$1@nnrp1.deja.com...
> > #!/usr/bin/perl -w
> >
> > use strict;
> >
> > main();
> > exit;
> >
> > sub main {
> >     my $v = 10;
> >
> >     while($v > 0) {
> >         {
> >             if ($v > 5) {
> >                 print "One\n";
> >                 $v--;
> >                 next;
> >             }
> >         }
> >         {
> >             if ($v > 0) {
> >                 print "Two\n";
> >                 $v--;
> >                 next;
> >             }
> >         }
> >         last;
> >     }
> > }
> >
> > The output from this program is:
> > One
> > Two
> >
> > I expected it to be:
> > One
> > One
> > One
> > One
> > One
> > Two
> > Two
> > Two
> > Two
> > Two
> >
> > This is Perl 5.005_03 on FreeBSD 4.1-stable
> >
> > Is this a bug?  Does this code behave the same on
> > 5.6?
> >
>
> Actually I think it's just a weird indenting style and strange use of
> blocks.
>
> This does what you are trying to achieve:-

Um, no it doesn't.

>
> #!/usr/bin/perl -w
> use strict;
>
> main();
> exit;
>
> sub main {
>     my $v = 10;
>         while($v > 0) {
>         if ($v > 5) {
>             print "One\n";
>             $v--;
>             next;
>         }
>         if ($v > 0) {
>             print "Two\n";
>             $v--;
>             next;
>         }
>     last;
>     }
> }
>
> You have superfluous opening and closing braces which means you are
not
> "next"ing into what you think you are.
>
> Also the "last" is really not doing much since $v must be <= 0 to get
> there anyway.

Well, I thought it was normal to post a _small_ piece of code that
demonstrated the behavior that I was trying to demonstrate.

Did you want me to post the actual (very long) piece of code and let
everyone sort through it???  Well, did you?

The braces, and the 'last' are necessary in the actual code.


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


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

Date: Sat, 09 Sep 2000 01:24:30 GMT
From: elliotfinley@my-deja.com
Subject: Re: Is this a bug or a feature?
Message-Id: <8pc3ft$76r$1@nnrp1.deja.com>

In article <UeHt5.2039$Ok5.435074@news.uswest.net>,
  "Christopher M. Jones" <christopher_j@uswest.net> wrote:
>
> <elliotfinley@my-deja.com> wrote:
> > I expected it to be:
> > One
> > One
> > One
> > One
> > One
> > Two
> > Two
> > Two
> > Two
> > Two
>
> If you want that, then just do:
>
> print "One\n" x 5;
> print "Two\n" x 5;

Duh!  Why didn't I think of that?

>
> or, I could try cleaning up your code (ugh!)

No, please don't, as it's obvious that you don't have clue.

>
> #!/usr/bin/perl -w
>
> use strict;
>
> main();
> exit;
>
> sub main
>     {
>     my $v = 10;
>
>     while($v > 0)
>         {
>         if ($v > 5)
>             { print "One\n"; }
>         elsif ($v > 0)
>             { print "Two\n"; }
>         $v--;
>         }
>     }
>
> ###########
>
> What's with all the nexts and lasts?  Were they really necessary?
> Use nexts and lasts sparingly, the vast majority of the time you
> don't need them.  And why do you need a main()?  This isn't C
> ya know?  Perl is easy as pie, don't complicate it with junk from
> other idiosyncratic programming languages.
>
>


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


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

Date: Sat, 09 Sep 2000 01:20:09 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: New Perl Tutorial - www.perltutor.com
Message-Id: <slrn8rj426.8ll.tjla@thislove.dyndns.org>

I was shocked! How could Uri Guttman <uri@sysarch.com>
say such a terrible thing:
>>>>>> "GJ" == Gwyn Judd <tjla@guvfybir.qlaqaf.bet> writes:
>
>  >> Advocate "use warnings" over -w in most cases.  See also the perllexwarn
>
>  GJ> I don't have that one. Is the name right? It's referenced in the perlrun
>  GJ> manpage but I cannot find it anywhere. I'm running 5.6.0
>
>it's there. check the spelling as it has 2 l's.

whoops got it :)

>but pushing a 5.6 feature now is not a good idea IMO. i would wait until
>the next stable release which is aimed at fixing many of 5.6's ills.

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
Eating chocolate is like being in love without the aggravation.


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

Date: Sat, 09 Sep 2000 01:22:43 GMT
From: tjla@guvfybir.qlaqaf.bet (Gwyn Judd)
Subject: Re: New Perl Tutorial - www.perltutor.com
Message-Id: <slrn8rj470.8ll.tjla@thislove.dyndns.org>

I was shocked! How could lurker65535@my-deja.com <lurker65535@my-deja.com>
say such a terrible thing:
>In article <slrn8rhudn.8ll.tjla@thislove.dyndns.org>,
>  tjla@guvfybir.qlaqaf.bet (Gwyn Judd) wrote:
>> You have an error in the section on strings. You say the literal
>> 'C:\\AUTOEXEC.BAT' is interpolated into C:\AUTOEXEC.BAT which is
>clearly
>> wrong.
>You would think that, but \\ and \' in single-quoted strings are in fact
>interpreted.  Other escape sequences are passed through untouched:

hmmm...interpolating \\ in a single quoted string is pointless (and
annoying, meaning you need to double your backslashes if you actually
did want to print two of them.

>print '\\\\';                     # \\

My point exactly

-- 
Gwyn Judd (print `echo 'tjla@guvfybir.qlaqaf.bet' | rot13`)
PRELATE

n. A church officer having a superior degree of holiness and a fat
preferment. One of Heaven's aristocracy. A gentleman of God.


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

Date: 09 Sep 2000 03:59:24 GMT
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Perl-native code for finding mail exchanger: nslookup -q=mx  some.domain?
Message-Id: <39B9B332.7DF2B69F@attglobal.net>

bryl@my-deja.com wrote:
> 
> Hi - I have a script that check's a user's email to make certain
> the domain name exists. I have 2 system nslookup calls, one the regular
> 
>         nslookup $domain
> 
> the second:
> 
>         nslookup -q=mx $domain
> 

For both the solution is simple...

use Net::DNS;

http://search.cpan.org/doc/MFUHR/Net-DNS-0.12/lib/Net/DNS.pm


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

Date: Sat, 09 Sep 2000 01:49:08 GMT
From: bryl@my-deja.com
Subject: Perl-native code for finding mail exchanger: nslookup -q=mx some.domain?
Message-Id: <8pc4ue$8j9$1@nnrp1.deja.com>

Hi - I have a script that check's a user's email to make certain
the domain name exists. I have 2 system nslookup calls, one the regular

	nslookup $domain

the second:

	nslookup -q=mx $domain

If both fail, it seems likely that the user didn't enter a correct
domain name in their email. I'd like to replace both calls with perl-
native code. The first one is easy enough:

unless (my $addr = gethostbyname $domain) {
	error("Invalid domain name in your email address.");
}

but how can I substitute a perl-specific call for the second,
nslookup -q=mx $domain  query?

Thanks in advance for any help.

Lars Bryant


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


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

Date: Fri, 8 Sep 2000 22:22:30 -0400
From: Jeff Pinyan <jeffp@crusoe.net>
Subject: Re: Regular Expressions
Message-Id: <Pine.GSO.4.21.0009082216450.23350-100000@crusoe.crusoe.net>

On Sep 9, Abigail said:

>Dietmar Staab (dietmar.staab@t-online.de) wrote on MMDLXVI September
>() 
>() /(["'<])(.*?)[\1>]/ and print $2;
>
>    /(["'<])(.*?)[\1>]/ and print $2;

I believe this is because character classes must be know at regex-compile
time.  \1 is not known until DURING the regex.  What DOES [\1]
become?  I'm quite curious.  -mre=debug tells me nothing useful.

-- 
Jeff "japhy" Pinyan     japhy@pobox.com     http://www.pobox.com/~japhy/
PerlMonth - An Online Perl Magazine            http://www.perlmonth.com/
The Perl Archive - Articles, Forums, etc.    http://www.perlarchive.com/
CPAN - #1 Perl Resource  (my id:  PINYAN)        http://search.cpan.org/



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

Date: Sat, 09 Sep 2000 01:26:39 GMT
From: Joe Johnston <jjohn@cs.umb.edu>
Subject: Re: using "|" as plain text in scripts (perl win)
Message-Id: <39B991C6.686179B1@cs.umb.edu>

aqutiv@my-deja.com wrote:
> 
> In article <39B8AE9F.31140C02@bmjgroup.com>,
>   Kourosh A Mojar <kmojar@bmjgroup.com> wrote:
> > dear all,
> >
> > im been trying to use "|" (pipe?) as pain text for creating flat
> > database files. but does not allow my scripts to work properly. ive
> > tried \| to try and cancel its command features but unsuccessful. i
> > haven't found any examples in books and was hoping someone could give
> me
> > a quick fix. can any one advise me on what is the best way to do this.
> >
> > thanking you in advance and for your kind attention,
> >
> > kourosh a mojar
> >
> 
> What was the exact line you used??
> You need to paste that in such sitautations, you know...
> 
> @fields = split /\|/, $line; #works fine
> 
> in any case... The same char might be used inside the fields,
> so parhaps you'll want to use something longer, such as ':x:'.
> 

Another great idea is to use a non-printing character for 
the delimiter, like \x02. Find a character that is "impossible"
to occur as data. 

I'm uncertain what "does not allow my scripts to work properly" 
means. If you mean that you can't read back your information, 
perhaps aqutiv's split solution will help. 

Keep on keepin' on.

-- 
----------------
Joe Johnston
http://aliensaliensaliens.com


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

Date: Sat, 09 Sep 2000 02:36:06 GMT
From: Joe Johnston <jjohn@cs.umb.edu>
Subject: Re: Variable not accepting value
Message-Id: <39B9A20B.7499399E@cs.umb.edu>

dwb1@home.com wrote:
> 
> I'm having problems occasionally with variables not accepting a value.

Wow. I tried to not accept the Stevie Winwood album from a CD club once, 
but I ended up buying it to avoid the hassle. 
 
> for example, in the function below, "$in{QUESTION_PATH}" will not accept
> the blank value so that the string can be re-built.  As a result, the
> variable is now twice as long instead of a couple characters smaller.

Simple assignments like this don't fail, unless there's magic in that
%in hash. Are you using mod_perl or Fast CGI perhaps? These can "clutter
your workspace" and leave variables in an unexpected condition after 
several runs. I would fire up the perl debugger and run this script 
through it. Although your assignment of an empty string to the key 
QUESTION_PATH should not fail, you may experiment with the 
delete operator. 

delete $in{QUESTION_PATH}; 

> sub RemoveLastQuestion
> {
>         my @path = split(/^A/, $in{QUESTION_PATH});
>         $in{QUESTION_PATH} = '';
> 
>         for (my $i = 0; $i < $#path; $i++) {
>                 if (length($path[$i]) > 0) {
>                         $in{QUESTION_PATH} .= "^A" . $path[$i];
>                 }
>         }
>         return $path[$#path];
> }

I would also suggest that your loop might look better like 
this:

for (my $i = 0; $i < @path - 1; $i++ ){ ... }

It is such a common mistake to forget that $#path is the last index 
of the array @path. You might want to emphasis that you are not going
to process the last element of the array. Also, the control-A 
character cannot be written like '^A' in Perl. It is a hex 01 
character. Are you trying to split on this non-printable character or 
the two character sequence carat-A? I assumed you wanted the single 
character. I apologize if I misunderstood.

If $in is a global variable, it can be confusing to maintainers to 
change it inside a subroutine. It is good style to explicitly pass 
in the hash as a reference (and document subroutine!) to let your 
maintainers know that you intend to alter that variable.

Another way to write this function without regexes is:

sub RemoveLastQuestion{
    my $hr_in = shift; # get the hashref 

    # split on a ctrl-a	
    my @path = split(/\x01/, $hr_in->{QUESTION_PATH});

    # last could be empty, but that's fine
    my $last = pop @path; 

    # stuff all the non-empty values back into the hash
    $hr_in->{QUESTION_PATH} = join "\x01", grep { length } @path;

    return $last;   
} 
 
All's well that ends. Well.

-- 
----------------
Joe Johnston
http://aliensaliensaliens.com


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

Date: 9 Sep 2000 02:38:09 GMT
From: Tina Mueller <tina@streetmail.com>
Subject: Re: Variable not accepting value
Message-Id: <8pc7qg$cdg2l$2@ID-24002.news.cis.dfn.de>

hi,
In comp.lang.perl.misc dwb1@home.com wrote:

> I'm having problems occasionally with variables not accepting a value.

> 	my @path = split(/^A/, $in{QUESTION_PATH});

without looking too much at the rest of the code, this
seems wrong to me.
what are you splitting here?
just remove the first "A" would have the same effect.
maybe you want to split on "^A",
and not on "A" at the beginning of the string.
remember from
perldoc perlre
that "^" is special in regexes.
split on /\^A/ will do the trick. i hope
that's the error, as I said, didn't look at the rest.

tina


-- 
http://tinita.de    \  enter__| |__the___ _ _ ___
tina's moviedatabase \     / _` / _ \/ _ \ '_(_-< of
search & add comments \    \__,_\___/\___/_| /__/ perception
please don't email unless offtopic or followup is set. thanx


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

Date: Sat, 9 Sep 2000 03:14:51 +0200
From: tony@svanstrom.com (Tony L. Svanstrom)
Subject: Re: website
Message-Id: <1egnmcy.1ig3rj11lqjtxcN%tony@svanstrom.com>

Abigail <abigail@foad.org> wrote:

> Wonderful! There are only 2354 billion other webpages full with [INLINE].
> What an original concept!

Time for Abigail to stop using Lynx all the time? ;-)


     /Tony
-- 
     /\___/\ Who would you like to read your messages today? /\___/\
     \_@ @_/  Protect your privacy:  <http://www.pgpi.com/>  \_@ @_/
 --oOO-(_)-OOo---------------------------------------------oOO-(_)-OOo--
   on the verge of frenzy - i think my mask of sanity is about to slip
 ---ôôô---ôôô-----------------------------------------------ôôô---ôôô---
    \O/   \O/  ©99-00 <http://www.svanstrom.com/?ref=news>  \O/   \O/


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

Date: 09 Sep 2000 02:15:21 GMT
From: abigail@foad.org (Abigail)
Subject: Re: website
Message-Id: <slrn8rj77u.b1k.abigail@alexandra.foad.org>

Tony L. Svanstrom (tony@svanstrom.com) wrote on MMDLXVI September
MCMXCIII in <URL:news:1egnmcy.1ig3rj11lqjtxcN%tony@svanstrom.com>:
-: Abigail <abigail@foad.org> wrote:
-: 
-: > Wonderful! There are only 2354 billion other webpages full with [INLINE].
-: > What an original concept!
-: 
-: Time for Abigail to stop using Lynx all the time? ;-)


The experience of viewing such pages with MSIE + Jaws [1] doesn't 
translate well to Usenet.


[1] A program to read out what's on the screen.



Abigail
-- 
@;=split//=>"Joel, Preach sartre knuth\n";$;=chr 65;%;=map{$;++=>$_}
0,22,13,16,5,14,21,1,23,11,2,7,12,6,8,15,3,19,24,14,10,20,18,17,4,25
;print@;[@;{A..Z}];


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

Date: Sat, 09 Sep 2000 01:57:56 GMT
From: Joe Johnston <jjohn@cs.umb.edu>
Subject: Re: what is the best way to get the lastest line from a file?
Message-Id: <39B99916.CB811C4B@cs.umb.edu>

Fu Kai wrote:
> 
> hi,
> I want to only get the lastest line from a *HUGE* plain text file(about
> 20M),
> and i think it is not a efficient way to catch it just read lines one by
> one,
> so what is the best way to do it? and how?
> 
> Any help is appreciated!!

You have no doubt read the other responses about 
File::Backward and using the external Unix command 
tail(1). I would choose tail(1) if it was most 
convenient. I submit the code below for your
amusement. It is all Perl and will return the 
last line of non-newline text in a file. It
was tested on Linux. Your mileage may vary, 
so please experiment. 

This is a script which expects a filename 
on the command line. The heart of it is 
the function 'get_last_line', which uses 
the seek() function to walk backwards 
through a file, ignoring trailing newlines. 
It is very weird Perl because it looks 
at the file character by character. I 
haven't had to do this since my bad old 
C/Pascal days. 

You may not wish to chop off the trailing 
newlines. You can get rid of the state 
variable $seen_non_newline if that is your 
wish.

Hasta luego.

---begin---
my $infile = shift || die "need a filename";

print 
    "last line was:\n",
    get_last_line($infile), 
    "\n";

#------
# subs
#------
sub get_last_line{
    my $file = shift || return;
    
    open FH, $file or die "Oops: $!";

    my $last             = '';
    my $i                = 1;
    my $seen_non_newline = 0;

    while( seek FH, -$i++, 2 ){
	my $buf;
	read FH, $buf, 1;
	if( $buf eq "\n" ){
	    next unless $seen_non_newline;
	    last;
	}else{
	    $seen_non_newline++;
	    $last = $buf . $last;
	}
    }
    close FH;

    return $last;
}
----end----

-- 
----------------
Joe Johnston
http://aliensaliensaliens.com


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

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


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