[10348] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3941 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat Oct 10 09:07:29 1998

Date: Sat, 10 Oct 98 06:00:20 -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           Sat, 10 Oct 1998     Volume: 8 Number: 3941

Today's topics:
        bug in this subroutine zobsky@my-dejanews.com
        can anyone figure out the bug in this subroutine <balamuru@cs.unt.edu>
        can anyone help me debugging this "simple"subroutine zobsky@my-dejanews.com
    Re: can anyone help me debugging this "simple"subroutin <jdf@pobox.com>
        CGI search results and breakup output? <noels@ozinet.zip.com.au>
    Re: Checking file size and date in Perl Win32 (Larry Rosler)
        crypt function in perl <see@bottom.of.sig>
    Re: How do I use die? <jeff@vpservices.com>
    Re: How do you save a state? <gellyfish@btinternet.com>
    Re: HTML extract problem <gellyfish@btinternet.com>
        Issuing remote commands trough sockets. <cfarley@mlink.net>
    Re: Newbie question RE: SSI and .cgi scripts on NT4 <adrian@pearl.demon.co.uk>
    Re: Newbie to Linux and Perl (Roland Schneider)
    Re: Newbie to Linux and Perl <gellyfish@btinternet.com>
        problem with a sub-routine <balamuru@silo.csci.unt.edu>
    Re: problem with a sub-routine <Arved_37@chebucto.ns.ca>
        Problem with perlmodules (Hampus Brynolf)
    Re: Problems Using a Compare Subroutine with Sort droby@copyright.com
    Re: Problems with substr (re- posted) <gellyfish@btinternet.com>
    Re: Q: Any List of Win32 Error Codes ? <gellyfish@btinternet.com>
    Re: Random number in perl. (Fritz W Feuerbacher)
        re newbie question <samwang@freewwweb.com>
    Re: regexps and cntl chars (John Moreno)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: Sat, 10 Oct 1998 08:17:07 GMT
From: zobsky@my-dejanews.com
Subject: bug in this subroutine
Message-Id: <6vn562$dpo$1@nnrp1.dejanews.com>

Hi, all out there,

I am trying to construct a language parser but am being held up by this kind
of bug. This segment of code and the associated subroutine analyses
thecontents of an array @str.

I first point to the first member of the array (noun) I then call the
subroutine (for case np1 defined by the string $next). I intend for the
subroutine to  goto case noun but it seems to go the case adjective ( $x is
incremented in the output)

Can anyone help me debug this tiny piece of code,please????

Also, could someone show me how to impliment case structure in perl, i'm
guessing it
might be a more robust solution, but my text makes no mention of case
structures.

Help much appreciated

Vinay B.
balamuru@cs.unt.edu

#code starts here

$next = "np1";
$x = 0;

@ str = ("noun", "noun2", "noun");

print "initially, next is $next and x is $x and str() points to $str[$x] \n";

do &np1($str[$x], $x, $next);

print "finally, next is $next and x is $x and str() points to $str[$x]\n";


sub np1
{
    if ($next ne "np1")
    {
        $next;
    }
    else
    {
        if ($str[$x] == "adjective")        #case adjective
        {
            $x++;
            $next = "np1";
        }
        elsif ($str[$x] == "noun")        #case noun
            {
            $next = "np2";
        }
        else
        {
            $next = "fail";
        }
    }
}

#code ends here

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Sat, 10 Oct 1998 02:57:48 -0500
From: vinay balamuru <balamuru@cs.unt.edu>
Subject: can anyone figure out the bug in this subroutine
Message-Id: <361F137C.DFC7B62B@cs.unt.edu>

Hi, all out there,

I am trying to construct a language parser but am being held up by this
kind of bug.
This segment of code and the associated subroutine analyses thecontents
of an array @str.

I first point to the first member of the array (noun)
I then call the subroutine (for case np1 defined by the string $next). I
intend for the subroutine to  goto case noun but it seems to go the case
adjective ( $x is incremented in the output)

Can anyone help me debug this tiny piece of code,please????

Also, could someone show me how to impliment case structure in perl, i'm
guessing it might be a more robust solution, but my text makes no
mention of case structures.

Help much appreciated

Vinay B.
balamuru@cs.unt.edu

#code starts here

$next = "np1";
$x = 0;

@ str = ("noun", "noun2", "noun");

print "initially, next is $next and x is $x and str() points to $str[$x]
\n";

do &np1($str[$x], $x, $next);

print "finally, next is $next and x is $x and str() points to
$str[$x]\n";


sub np1
{
    if ($next ne "np1")
    {
        $next;
    }
    else
    {
        if ($str[$x] == "adjective")        #case adjective
        {
            $x++;
            $next = "np1";
        }
        elsif ($str[$x] == "noun")        #case noun
            {
            $next = "np2";
        }
        else
        {
            $next = "fail";
        }
    }
}

#code ends here



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

Date: Sat, 10 Oct 1998 08:10:26 GMT
From: zobsky@my-dejanews.com
Subject: can anyone help me debugging this "simple"subroutine
Message-Id: <6vn4pg$d86$1@nnrp1.dejanews.com>

Hi, all out there,

I am trying to construct a language parser but am being held up by this kind
of bug. This segment of code and the associated subroutine analyses
thecontents of an array @str.

I first point to the first member of the array (noun) I then call the
subroutine (for case np1 defined by the string $next). I intend for the
subroutine to  goto case noun but it seems to go the case adjective ( $x is
incremented in the output)

Can anyone help me debug this tiny piece of code,please????

Also, could someone show me how to impliment case structure in perl, i'm
guessing it
might be a more robust solution, but my text makes no mention of case
structures.

Help much appreciated

Vinay B.
e mail:balamuru@cs.unt.edu

#code starts here

$next = "np1";
$x = 0;

@ str = ("noun", "noun2", "noun");

print "initially, next is $next and x is $x and str() points to $str[$x] \n";

do &np1($str[$x], $x, $next);

print "finally, next is $next and x is $x and str() points to $str[$x]\n";


sub np1
{
    if ($next ne "np1")
    {
        $next;
    }
    else
    {
        if ($str[$x] == "adjective")        #case adjective
        {
            $x++;
            $next = "np1";
        }
        elsif ($str[$x] == "noun")        #case noun
            {
            $next = "np2";
        }
        else
        {
            $next = "fail";
        }
    }
}

#code ends here

-----== Posted via Deja News, The Leader in Internet Discussion ==-----
http://www.dejanews.com/rg_mkgrp.xp   Create Your Own Free Member Forum


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

Date: 10 Oct 1998 14:26:08 +0200
From: Jonathan Feinberg <jdf@pobox.com>
To: zobsky@my-dejanews.com
Subject: Re: can anyone help me debugging this "simple"subroutine
Message-Id: <m31zogsivz.fsf@joshua.panix.com>

zobsky@my-dejanews.com writes:

> do &np1($str[$x], $x, $next);

The word "do" is deprecated in this context, and doesn't mean what you 
think it means. To invoke a subroutine in Perl, simply say

   subroutine(arg1, arg2, ...);

You are passing parameters to &np1, but &np1 is not looking at
them. Why are you passing them?

> sub np1
> {
>     if ($next ne "np1")
>     {
>         $next;

This means that the subroutine sometimes evaluates to $next, but you
invoke the subroutine in a void context. Why are you returning a value?

>         if ($str[$x] == "adjective")        #case adjective

Oops. You mean 'eq' instead of '=='.

You *really* need to put the -w switch in the #! line of your script,
which will give you instructive warning messages. Once you've fixed
those == bugs, another will arise. I'll leave that one as a surprise.

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Sat, 10 Oct 1998 17:31:15 +1000
From: "Noel Sampol" <noels@ozinet.zip.com.au>
Subject: CGI search results and breakup output?
Message-Id: <6vn24a$9o3$1@the-fly.zip.com.au>

Hi,

I'm trying to write a Perl CGI script that searches for keywords in multiple
ASCII text delimitted databases.  My question is how to show the results in
lumps of 10.  I thought I could store the results in a temporary array but
how do I traverse this temporary array if the search CGI script is called
multiple times thru an HREF tag in the HTML created by the CGI script.  That
is, the first 10 is shown then an HREF tag is created by the CGI script
which passes a place counter (where we are up to in search results) that
calls the search SCRIPT again to display the next 10.

I wonder also if I'll have to create temporary files to store the results
but this would be difficult to keep track of considering that multiple
people could be doing a search at the same time.

Any ideas?

Sorry if I'm askin' a stupid question ;-)

Thank you

Noel Sampol
noels@ozinet69.zip.com.au   (e-mail)
* NOTE: Please remove '69' if replying by e-mail





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

Date: Fri, 9 Oct 1998 23:07:33 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Checking file size and date in Perl Win32
Message-Id: <MPG.1088997c5844ef179898a6@nntp.hpl.hp.com>

[Posted to comp.lang.perl.misc and copy mailed.]

In article <01bdf3ef$b31d0a00$598d87d1@Calvin.daugherty.com> on 10 Oct 
1998 01:47:11 GMT, Joe H. <hteam@inlink.com> says...
> How do I do this in perl for Win32?  Is it a module and if so where do I go
> to get it?  Thanks in advance.

Exactly the same as for Unix.  It is in the core software.

Look at the documentation for the 'stat' function (though some of the 
returned values won't be meaningful) and the file-test operators '-s' 
(for size) and '-A', '-C', and '-M' for various dates (access, creation, 
and modification). 

-- 
(Just Another Larry) Rosler
Hewlett-Packard Laboratories
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Sat, 10 Oct 1998 13:10:07 +0100
From: Ryan <see@bottom.of.sig>
Subject: crypt function in perl
Message-Id: <361F4E9F.370E461@bottom.of.sig>

Got perl yesterday .. </end of introduction>

first perl script i have written is a perl version of crack
this is what i have done so far ..

crypt.pl <----- takes a username and password via ARGV[numbers]
                prints to a file with password crypted.
                this was just purely for testing purposes

crack.pl <----- takes a word via ARGV[0] encrypt's it and search's
                through the password file for a match 
                this works and will match up with the file created
                with crypt.pl

cracklots.pl <- this takes words from a file encryts them and searchs
		through the password file for match's
                This works for some of the encrypted passwords but 
                wont read all passwords from list and compare


So. 
what do i encrypt a word from a file with to get a match with crypt.pl
or even better what are linux/unix passwords encrypted with.

no unkind remarks about my coding please..

------- cut here ----------
# start crypt.pl
$file = "password.txt";    # just supplying variable with filename
$username = $ARGV[0];      # carries name 
$password = $ARGV[1];      # carries unencrypted password
$stuff = $ARGV[2];         # just for extra info
$encrypted = crypt ($password, "");      #encrypt's the password
                                    #just a simple print of usage
print "\nOk - Usage perl crypt.pl username password extra\n";
open (PWD, ">>$file");    #opens file in append mode
                          #writes the data and splits them up using :
print PWD $username, ":", $encrypted, ":", $stuff, "\n";
close (PWD);              #closes the file
# End crypt.pl
----------------------------

---cut here --
# start cracklots.pl

$passlist = "password.txt";  # Just an example could be /etc/passwd
$wordlist = "words.txt";     # Our word list
$capture = "capture.txt";    # not used in this one yet but will be broken 
                             # accounts and info of the likes
open (PWD, $passlist);         #opens out password file
while (<PWD>)
   {                                              #variables in file
   ($fname, $encrypted, $stuff) = split ( /:/);   #split-up by :
                open (WRD, $wordlist);
                while (<WRD>)
                        {
                        ($password, $etc) = split (/,/);
                        $test = crypt ($password, "");
#                       print "Password = ", $password;         
#                       print "encrypted file = $encrypted ";
#                       print "test = $test ";
                        if ($test eq $encrypted)
                        {
                        print "Password is ", $password, "for ", $fname;
                        }}}
close (PWD);            #closes the password file
# End cracklots.pl
--------------

# start cracklots.pl

$passlist = "password.txt";  # Just an example could be /etc/passwd
$wordlist = "words.txt";     # Our word list
$capture = "capture.txt";    # Our capture of broken accounts and passwords

open (PWD, $passlist);         #opens out password file
while (<PWD>)
   {                                              #variables in file
   ($fname, $encrypted, $stuff) = split ( /:/);   #split-up by :
		open (WRD, $wordlist);
		while (<WRD>)
			{
		  	$password = <WRD>;
			$test = crypt ($password, $encrypted);
			print "Password = ", $password;         
#			print "encrypted file = $encrypted ";
			print "test = $test \n";
			if ($test eq $encrypted)
				{
				print "Password is ", $password, "for ", $fname;
				}}}
close (PWD);            #closes the password file
# End cracklots.pl

-----

apologies for bandwidth etc..
if replying to this message please cut out as much you can (within reason)

thanks in advance .. these scripts will be part of a system
security checking program and if ever finished will be posted .

-- 
 manicx at iname dot com <-- anti tinned meat product you know what to do


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

Date: 10 Oct 1998 06:11:32 GMT
From: Jeff Zucker <jeff@vpservices.com>
Subject: Re: How do I use die?
Message-Id: <361EF9A2.F605196E@vpservices.com>

brettr wrote:
> #!/usr/bin/perl
> chdir('/user/printer')or die;
> [snip]
> I get Internal Server Error.

Mistake #1: you left off -w on the first line.  Always use perl's
warnings to find out what is going wrong.

Mistake #2: you left off $! on the second line so you won't know what
the error message is when it dies.

Mistake #3: (and this is the big one) there's no way you can find out
what went wrong by accessing that script from your browser - you have to
run it on the command line to see what is going on.  Put in the -w and
the $! and run it from the command line and you will find out why the
script isn't working.  That is what die is for - to exit the program
when something goes wrong so you can find out what went wrong.  You can
use the CGI::CARP module to see a lot of specific error messages in your
browser but even then it's best to test your scripts on the command line
first so you can see where and often why the die exited the script.

My guess BTW is that the script died because the directory you tried to
chdir to didn't exist - either a typo or wrong path.

HTH,

- Jeff

brettr wrote:
> 
> I'm running this simple little script for testing:
> 
> #!/usr/bin/perl
> chdir('/user/printer');
> print "Content-type: text/html\n\n";
>    print "<HEAD>\n";
>    print "   <TITLE>New User</TITLE>\n";
>    print "</HEAD>\n";
>    print "<BODY>\n";
>    print "<P><HR><P></BODY></HTML>\n";
> 
> It runs fine. However, if I replace the second line with either of
> these, I
> get Internal Server Error.
> chdir('/user/printer')or die();
> chdir('/user/printer') or die;
> 
> Even using the $! I get the error. From what I've read, that script
> should
> work. Any suggestions?
> 
> brettr


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

Date: 10 Oct 1998 08:14:54 +0100
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: How do you save a state?
Message-Id: <6vn1he$bp$1@gellyfish.btinternet.com>

On Fri, 09 Oct 1998 14:36:19 -0700 Kenneth Hunt <kchunt@mail.hac.com> wrote:
> I need to keep information on a file pathname which is generated in one
> frame of frameset A, and use that info in another frame in frameset B.
> How can I do that? 
> 
> The info in question is passed to frameset B, but how do you transfer
> that info to a frame in frameset B??

And the Perl question is ?

If you are using Perl somewhere in there you might do worse than read the
documentation for CGI.pm - especially the section entitled:

"Working with Netscape frames"

However you slice it the Perl content of this is going to be so small that
this will never be an appropriate place to ask this kind of question.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: 10 Oct 1998 09:11:21 +0100
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: HTML extract problem
Message-Id: <6vn4r9$fv$1@gellyfish.btinternet.com>

On 9 Oct 1998 23:17:46 GMT Kay Molkenthin <molkiheg@sp.zrz.tu-berlin.de> wrote:
> Jonathan Feinberg <jdf@pobox.com> wrote:
>>molkiheg@sp.zrz.tu-berlin.de (Kay Molkenthin) writes:
>>
> 
>>If you'd show us the perl code that's giving you trouble, we'll be
>>better able to help you.
> 
> Hi,
> 
> sorry but I am not able to because I am not experienced in searching & cutting
> text with perl.
> 

You mean you want us to do your work for you when you dont want to go out
and hire a programmer who can ?

> Perhaps the HTML-code from this page can help you. This is the important part
> of each HTML-file:
> 

<snip>

You all most certainly want to be using something Like HTML::Parser.
What follows is a brief and flawed example of how you might achieve what you
want using that module:


#!/usr/bin/perl

package Blah;

@ISA = qw(HTML::Parser);
require HTML::Parser;

use vars qw($infield $inrecord,$intable);

$parser = new Blah;

$parser->parse_file("blah.htm");

sub start()
{
   my($self,$tag,$attr,$attrseq,$orig) = @_;
   
   $intable++ if($tag eq "table");

   $inrecord++ if($tag eq "td");
   
   $infield++ if($tag eq "b");
}

sub text()
{
   my ($self,$text) = @_;
   
   if ($intable && $inrecord && $infield )
     {
       $text =~ s/.*?: //gs;

       print $text,"\;" if $text;
     }
}


sub end()
{
   my ($self,$tag) = @_;
   
   $intable-- if($tag eq "table");

   if($tag eq "td")
    {
     $record--;
     print "\n";
    }
   
   $infield-- if($tag eq "b");
}

1;
__END__

This is assuming that your html is in a file called "blah.htm".  It is left
as an exercise in reading the documentation as to how you might apply this
to multiple files.  If you have any difficulty with what is going on in this
code you should look at the documentation for HTML::Parser.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: Mon, 05 Oct 1998 16:59:34 -0400
From: Farley Christian <cfarley@mlink.net>
Subject: Issuing remote commands trough sockets.
Message-Id: <36193336.41C6@mlink.net>

Most of the examples that i've seen on that subject have the server
print "hello world" on the client.

How can i have a script execute a command on a remote machine (like rsh)
and collect back the output from that command?

Thanks in advance!

-- 
Christian Farley		AtralTech Inc.	
Administrateur Systeme	

cfarley@animation.astral.com
514-939-5088 #3121

2100 Ste-Catherine Ouest / Suite 900		
Montreal, PQ, Canada
H3H 2T3


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

Date: Sat, 10 Oct 1998 13:35:57 +0100
From: Adrian Albin-Clark <adrian@pearl.demon.co.uk>
Subject: Re: Newbie question RE: SSI and .cgi scripts on NT4
Message-Id: <xMGq5DAtS1H2EwOO@pearl.demon.co.uk>

>If you want to do the <!--#exec cgi ... --> stuff referenced above you need
>SSI.
>
>Because that stuff IS SSI (which means Server-Side-Includes by the way).
>
>To install it on an NT server? Well first you install webserver software on
>you NT server...  The documentation for that webserver software may tell you
>where to go next.
>

Webserver is IIS2 as bundled with NT Server 4. The docs don't say how to
set up SSI, in fact they do not even mention it. That's why I am asking
here. Perhaps I should redirect this question to an NT4 newsgroup
instead.

-- 
Adrian Albin-Clark


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

Date: Sat, 10 Oct 1998 09:51:51 GMT
From: rs@9810.fish.ch (Roland Schneider)
Subject: Re: Newbie to Linux and Perl
Message-Id: <36202cc3.39184524@news.fish.ch>


Your example is not a cgi-script ie cant run by the webserver.
It has to return the correct header as the first line (usually
"Content-type...") followed by 2 newlines ("\n\n").
After this, you may print out whatever you want :)
Read some more of your book, there shure will be lots of examples.

Roland

"Raul Trujillo" <raul_t@pacbell.net> wrote in comp.lang.perl.misc:

>I just installed Red Hat Linux 5.1 on my PC.  I'm trying to get Perl to =
run
>some of the scripts I've put in the cgi-bin (/home/httpd/cgi-bin).  I've
>started with the very first script on the book, "Hello World."
>
>I have typed it in this format:
>
>#!/usr/bin/perl
>print "Hello, world!\n";
>
>and put it in the cgi-bin.  I saved it with a ".cgi" extension.  I chmod=
 the
>cgi-bin with "755."  And I created a link to the script in an HTML page =
in
>this manner (a href=3D"file:/home/httpd/cgi-bin/sample.cgi").  After I =
click
>on the link, I get the sample script on the Netscape Communicator 4.0
>browser and I get nothing but the same HTML page on KDE.  I have checked
>where my Perl program is, and it is in /usr/bin/perl.  Can anyone please
>tell me what am I missing?
>
>Thanks...
>
>raul_t@pacbell.net
>
>


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

Date: 10 Oct 1998 08:09:18 +0100
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Newbie to Linux and Perl
Message-Id: <6vn16u$bm$1@gellyfish.btinternet.com>

On Fri, 9 Oct 1998 18:15:55 -0700 Raul Trujillo <raul_t@pacbell.net> wrote:
> I just installed Red Hat Linux 5.1 on my PC.  I'm trying to get Perl to run
> some of the scripts I've put in the cgi-bin (/home/httpd/cgi-bin).  I've
> started with the very first script on the book, "Hello World."
> 
> I have typed it in this format:
> 
> #!/usr/bin/perl
> print "Hello, world!\n";
> 

There is absolutely nothing wrong with this.

I think you'll find however that this wont work in the CGI environment - 
try running it from the command line.  CGI programs have some extra 
responsibilities that those run in other environments do not.

> and put it in the cgi-bin.  I saved it with a ".cgi" extension.  I chmod the
> cgi-bin with "755."  And I created a link to the script in an HTML page in
> this manner (a href="file:/home/httpd/cgi-bin/sample.cgi").  

Now whatever made you think that this would do anything else other than
display the contents of the file.  The script is not being executed at all.
You are *asking* to display the contents of the file.

>                                                              After I click
> on the link, I get the sample script on the Netscape Communicator 4.0
> browser and I get nothing but the same HTML page on KDE.  I have checked
> where my Perl program is, and it is in /usr/bin/perl.  Can anyone please
> tell me what am I missing?
> 

You are basically missing an idea of how HTTP and CGI work.  It appears that
you believe Perl is synomomous with CGI.  You are trying to
run before you can crawl properly.  Try running the example scripts from
the command line. If you want to play with CGI then read the documentation
for your server and examine the example CGI code if it has any.

Read the perlrun manpage.

If you have questions about CGI please address them to an appropriate forum.

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: Sat, 10 Oct 1998 03:40:59 -0500
From: Vinay Balamuru <balamuru@silo.csci.unt.edu>
Subject: problem with a sub-routine
Message-Id: <Pine.GSO.3.93.981010033351.2015A-100000@silo.csci.unt.edu>

i apologise if this multiple posting is irritating anyone but i've been
having problems with my news software


I'm developing a grammatical parser and am ....stuck here!!
i would appreciate it if anyone could help me debug this routine
given the input parameters, i would expect the subroutine to choose case
noun, but it seems to be satisfied by case adjective. i cannot figure out
why

Also, it might be more robust to implimentt this using a "case"structure
but my textbook doesn't tell me how, could someone show me the syntactical
structure.


thousand thanks

Viay Balamuru
balamuru@cs.unt.edu 

#**************main program**************
$next = "np1";
$x = 0;

@ str = ("noun", "noun2", "noun");

print "initially, next is $next and x is $x and str() points to $str[$x]
\n";
do &np1($str[$x], $x, $next);
print "finally, next is $next and x is $x and str() points to $str[$x]\n";
#*************end of main program********


#***************subroutine starts here***********
sub np1
{
    if ($next ne "np1")
    {
        $next;
    }
    else
    {
        if ($str[$x] == "adjective")
        {
                $x++;
            $next = "np1";
        }
        elsif ($str[$x] == "noun")
        {
            $next = "np2";
        }
        else
        {
            $next = "fail";
        }
    }
}
#*******************end of routine*******************





Vinay G. Balamuru
________________________________________________________________________

<if it wasn't for the last minute, nothing would get done>
<The two most common elements in the universe are hydrogen and stupidity>
<If at first you don't succeed, skydiving is not for you>



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

Date: Sat, 10 Oct 1998 08:24:55 -0300
From: Arved Sandstrom <Arved_37@chebucto.ns.ca>
Subject: Re: problem with a sub-routine
Message-Id: <Pine.GSO.3.95.iB1.0.981010081251.4324A-100000@halifax.chebucto.ns.ca>

Here's an example subroutine that incorporates a case structure:

sub np2 {
   my ($array_val, $x, $next) = @_;

   my $ret;
   SWITCH: {
      ($next eq "np3") && do {$ret="np3", last SWITCH;};
      ($array_val eq "adjective") && do {$ret="np1", $x++, last SWITCH;};
      ($array_val eq "noun") && do {$ret="np2", last SWITCH;};
      $ret="fail";
   }

   ($x, $ret);
}

For *your* global variables (i.e. variables being used in main) call this
sub as:

($x, $next) = np2($str[$x], $x, $next);

NOTE: if you use a subroutine, try to confine effects to what you're
passing out in the return values. Reset your variables that way. Keep sub
variables scoped (lexically) using my(). Otherwise you'll lose track of
what's being changed where.

You can extract just the switch from the sub, and use that in your main
program, in which case you're addressing your actual variables. In this
situation, try

SWITCH: {
   ($next eq "np3") && do {$next="np3", last SWITCH;};
   ($str[$x] eq "adjective") && do {$next="np1", $x++, last SWITCH;};
   ($str[$x] eq "noun") && do {$next="np2", last SWITCH;};
   $next="fail";
}
 and you can put this all in a loop.

This is just a quick one-off. I'll make no guarantees that I actually
followed your logic 100%, but I think it's close. :-)

Other point: in your original, you're using == to compare strings. Use eq.

Arved

On Sat, 10 Oct 1998, Vinay Balamuru wrote:

> I'm developing a grammatical parser and am ....stuck here!!
> i would appreciate it if anyone could help me debug this routine
> given the input parameters, i would expect the subroutine to choose case
> noun, but it seems to be satisfied by case adjective. i cannot figure out
> why
> 
> Also, it might be more robust to implimentt this using a "case"structure
> but my textbook doesn't tell me how, could someone show me the syntactical
> structure.



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

Date: Sat, 10 Oct 1998 11:56:06 GMT
From: hampus@globetree.org (Hampus Brynolf)
Subject: Problem with perlmodules
Message-Id: <361f49e8.1213652990@192.168.0.1>

I really think I got something wrong here...

What I want to do:
* manipulate a file from a perlscript (append information to sat.ini)
* then call a routine from another perl file (vfv.pm) that opens my
manipulated file (sat.ini) and create another output from the
information (eg. making a webpage from the sat.ini file)
* I want to keep the routine in a .pm file because I call the routine
from a number of different scripts.

What happens:
* everything seems to work BUT the changes done is done from the ini
file read BEFORE I changed the file.

My question:
* When i write :
use vfv.pm;
is that script actually executed, and the 'open' instructions in the
script performed?


/Hampus


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

Date: Sat, 10 Oct 1998 12:23:27 GMT
From: droby@copyright.com
Subject: Re: Problems Using a Compare Subroutine with Sort
Message-Id: <6vnjjv$ume$1@nnrp1.dejanews.com>

In article <361E6964.9AC57F95@min.net>,
  John Porter <jdporter@min.net> wrote:
> droby@copyright.com wrote:
> >
> > > All IPv7 addresses are four-letter words.   Neat!
> >
> > Unfortunately, it's a step backward.  After posting  this silliness, I went
> > looking at RFCs.  IPv6 addresses are 128 bits, and I'm sure you'll be happy
to
> > know the text representation is described in RFC 1884 as:
> >
> > <quote> The preferred form is x:x:x:x:x:x:x:x, where the 'x's are the
> > hexadecimal values of the eight 16-bit pieces of the address. </quote>
> >
> > I guess we'll just have to be twice as vulgar.
>
> Well, maybe they're four 32-bit characters.
> Unicode can do that, right?
> So you can be vulgar in vulcan.
>

Guess I should have looked at the Unicode spec while I was at my research.
I'll just have to learn vulcan.

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: 10 Oct 1998 09:22:56 +0100
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Problems with substr (re- posted)
Message-Id: <6vn5h0$go$1@gellyfish.btinternet.com>

On Thu, 8 Oct 1998 19:00:24 GMT John J. Alesse <jja@inforonics.com> wrote:
> Perl folk:
>  
>  I'm having a problem with substr in version 5.00550 of Perl. It seems
>  that the substr function has a hard time extracting strings that
> contain
>  non-printable (binary) data at or above \xC0 but only when used in a
>  subroutine. This becomes a problem in packages like CGI.pm since substr
>  is used to extract binary multipart form/data from the header.


It works fine for me (perl 5.005.02 linux 2.034)  :

A)  It might not be substr failing - check what you have got before you
    feed it to that function.

B)  Your OS might need to set binmode() if you are reading the data from
    a file or STDIN

C)  5.005.50 is not the latest of the development releases - have you tried
    this with the stable release ?

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: 10 Oct 1998 11:53:43 +0100
From: Jonathan Stowe <gellyfish@btinternet.com>
Subject: Re: Q: Any List of Win32 Error Codes ?
Message-Id: <6vnebn$128$1@gellyfish.btinternet.com>

In comp.lang.perl.misc Eisen Chao <echao@interaccess.com> wrote:
> 
> To All:
> 
> 
> Any one out there know where a list of all the returned error
> codes from Win32 modules like NetResources is ? I'm getting
> some non-zero error codes but I have no idea what they mean.
> 
> 
I couldnt get you a list but there is a Win32::* function that will
give you the text for an error. I.E.

use Win32;

if( .. somehting that might return non-zero .. )
{
   print Win32::FormatMessage(Win32::GetLastError());
}

/J\
-- 
Jonathan Stowe <jns@btinternet.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>


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

Date: 10 Oct 1998 05:17:45 GMT
From: fwf27775@pegasus.cc.ucf.edu (Fritz W Feuerbacher)
Subject: Re: Random number in perl.
Message-Id: <6vmqlp$5uc$2@news.cc.ucf.edu>

How about trying rand().

Eric Persson (persson@tkj.se) wrote:
: I need to make a random nr in perl. Someone got a simple syntax for
: this??
: Please help me and reply via e-mail!

: /Eric Persson
: persson@tkj.se

--


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

Date: Fri, 09 Oct 1998 23:55:44 -0500
From: Sam Wang <samwang@freewwweb.com>
Subject: re newbie question
Message-Id: <361EE8D0.66C15516@freewwweb.com>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
sure there's the * wildcard. but something has to be infront of it and
it'll only match zero or more of that. is there any way to make it match
zero or more of ANYTHING?</HTML>



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

Date: Sat, 10 Oct 1998 04:08:20 -0500
From: phenix@interpath.com (John Moreno)
Subject: Re: regexps and cntl chars
Message-Id: <1dgnxs6.1gkr0blxt967vN@roxboro0-030.dyn.interpath.net>

<pfeilgm@jmu.edu> wrote:

> Followup-To: pfeilgm@technomadic.org,comp.lang.perl.misc

That isn't the way to request a Cc, if you want a Cc use the
Mail-Copies-To header or request one in the body.


Cc NOT sent.

-- 
John Moreno


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

Date: 12 Jul 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Mar 98)
Message-Id: <null>


Administrivia:

Special notice: in a few days, the new group comp.lang.perl.moderated
should be formed. I would rather not support two different groups, and I
know of no other plans to create a digested moderated group. This leaves
me with two options: 1) keep on with this group 2) change to the
moderated one.

If you have opinions on this, send them to
perl-users-request@ruby.oce.orst.edu. 


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

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