[11398] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4996 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Feb 26 16:17:59 1999

Date: Fri, 26 Feb 99 13:13:51 -0800
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, 26 Feb 1999     Volume: 8 Number: 4996

Today's topics:
        Q: Why is this array not defined outside the subroutine (Effie Rover)
    Re: Q: Why is this array not defined outside the subrou <jglascoe@giss.nasa.gov>
    Re: Q: Why is this array not defined outside the subrou <jdf@pobox.com>
    Re: Q: Why is this array not defined outside the subrou (Effie Rover)
    Re: Q: Why is this array not defined outside the subrou (Effie Rover)
    Re: Q: Why is this array not defined outside the subrou <jdf@pobox.com>
    Re: Q: Why is this array not defined outside the subrou (Effie Rover)
        randomize sequence <kin@symmetrycomm.com>
    Re: randomize sequence <jglascoe@giss.nasa.gov>
    Re: randomize sequence <kin@symmetrycomm.com>
    Re: randomize sequence <Allan@Due.net>
    Re: randomize sequence <jglascoe@giss.nasa.gov>
    Re: randomize sequence (Abigail)
    Re: Re: Can perl do this? (Alan Young)
        reading form data <mimi@lino.com>
    Re: reading form data (Alastair)
        Reading from files <ceedas@cee.hw.ac.uk>
    Re: Reading from files <jglascoe@giss.nasa.gov>
    Re: Reading from files (Larry Rosler)
    Re: Reading from files <jackg@aloha.net>
        Reading/Writing from/to a process.... <wfunk@dev.tivoli.com>
    Re: Reading/Writing from/to a process.... (M.J.T. Guy)
    Re: Reading/Writing from/to a process.... (Alastair)
    Re: Reading/Writing from/to a process.... <Tony.Curtis+usenet@vcpc.univie.ac.at>
    Re: ReadParse confusion <nospam@geniusweb.com>
    Re: Real-time Browser Updating <dhenders@cpsgroup.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Thu, 25 Feb 1999 19:27:26 GMT
From: null@effierover.com (Effie Rover)
Subject: Q: Why is this array not defined outside the subroutine?
Message-Id: <36d6a278.278000955@news.iinc.com>

I have a problem with a piece of code - I'm traversing a tree, so I
wrote a recursive sub to work through it. At each node, I have either
a node list or a leaf list. If it's a node list, I want to check for
text matches (assuming I haven't already matched further on up this
same path). If it's a leaf list, I want to simply append it to an
array for later processing.

My problem is that while the recursive code works correctly and
gathers the correct data (tested by print statements), and while the
arrays I'm building are exactly what they should be within the routine
(tested by print statements), they fail to exist at all outside of it!
When I reference the arrays after leaving this routine, they're
empty???

This may be a simple problem - any help is appreciated. The source
code for the routine is below. I defined the arrays earlier in the
code in case it was a scoping issue. No difference.

[Please pardon my perl code - I'm not as proficient as I'd like to be.
Pointers on improving the code would be cool, too]

sub CountContainers {                                  
                                                       
  my ($node, $pathN, $pathT, $MatchPrev) = @_;         
  my (@NODE, @branches, @leaves, $Match, $TestString); 
                                                       
  @NODE = split(/\|/, $CONT[$node]);                   
  @branches = split(/\,/, $NODE[5]);                   
  @leaves = split(/\,/, $NODE[6]);                     
                                                       
  unless ($node == 1) {                                
    $pathN .= ',' . $NODE[0];                          
    $pathT .= '|' . $NODE[3];                          
  }                                                    
                                                       
  foreach $branch (@branches) {                        
    $Match = 0;                                        
    unless ($MatchPrev) {                              
      $Match = 1;                                      
      $TestString = lc $pathT . $CONT[$branch];        
      foreach $Word (@SearchWords) {                   
        unless (index($TestString, lc $Word) >= 0) {   
          $Match = 0;                                  
          last;                                               
        }                                                     
      }                                                       
    }                                                         
    if ($Match) {                                             
      push @CONTLIST, "${pathN},${branch}";                   
      push @CONTTITLELIST, "${pathT},$CONT[$branch]";         
      $MatchPrev = 1;                                         
    }                                                         
    CountContainers($branch,$pathN,$pathT,$MatchPrev);        
  }                                                           
                                                              
  # --- save Sites in this branch for later processing ---    
  if (@leaves) {                                              
    push @MATCHINGSITELIST, $pathN;                           
  }                                                           
}                                                             

Thanks in advance! ... Loy

Loy Ellen Gross AKA Effie Rover
The email address above goes straight to /dev/null :-)
effie -at- effierover -dot- com * http://www -dot- effierover -dot- com
Effie Rover's Fantasy Role Playing Gamer's Library


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

Date: Thu, 25 Feb 1999 17:07:00 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: Effie Rover <effie@effierover.com>
Subject: Re: Q: Why is this array not defined outside the subroutine?
Message-Id: <36D5C984.E1113612@giss.nasa.gov>

[courtesy copy sent to Effie]

Effie Rover wrote:
> 
> This may be a simple problem - any help is appreciated. The source
> code for the routine is below. I defined the arrays earlier in the
> code in case it was a scoping issue. No difference.

are "@CONTLIST", "@CONTTITLELIST", "@MATCHINGSITELIST" global variables?

perhaps you can try (at beginning of program):

use strict;
use vars qw(@CONTLIST @CONTTITLELIST @MATCHINGSITELIST);

--
"Pow!"
--Batman


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

Date: 25 Feb 1999 19:19:20 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: null@effierover.com (Effie Rover)
Subject: Re: Q: Why is this array not defined outside the subroutine?
Message-Id: <m3g17ukodz.fsf@joshua.panix.com>

null@effierover.com (Effie Rover) writes:

> When I reference the arrays after leaving this routine, they're
> empty???

>       push @CONTLIST, "${pathN},${branch}";                   
>       push @CONTTITLELIST, "${pathT},$CONT[$branch]";         
>     push @MATCHINGSITELIST, $pathN;                           

If this routine is in package Foo and you're calling it from package
main (or whatever) then those globals (which are really @Foo::CONTLIST
etc.) won't be defined in main.  I'm *guessing* that's the source of
your problem.  You may wish to either export those variables from Foo
or refer to them explicitly (@Foo::WHATEVER) from main.

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


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

Date: Fri, 26 Feb 1999 00:25:54 GMT
From: null@effierover.com (Effie Rover)
Subject: Re: Q: Why is this array not defined outside the subroutine?
Message-Id: <36d5e9a4.296224111@news.iinc.com>

On Thu, 25 Feb 1999 17:07:00 -0500, Jay Glascoe
<jglascoe@giss.nasa.gov> wrote:

>[courtesy copy sent to Effie]
>
>Effie Rover wrote:
>> 
>> This may be a simple problem - any help is appreciated. The source
>> code for the routine is below. I defined the arrays earlier in the
>> code in case it was a scoping issue. No difference.
>
>are "@CONTLIST", "@CONTTITLELIST", "@MATCHINGSITELIST" global variables?
>
>perhaps you can try (at beginning of program):
>
>use strict;
>use vars qw(@CONTLIST @CONTTITLELIST @MATCHINGSITELIST);

Tried something similar first, but not exactly the way you have it, so
I tried that just now. No dice. I get:

MATCH: 1,18,171 - |ADnD 1st Ed,171|||Greyhawk||100,108,109,110,46||18
MATCH: 1,2,159 - |ADnD 2nd Ed,159|||Greyhawk||167,310,322,323,324||2

The correct results from inside the sub, but nothing once outside it.

TIA ... Loy

Loy Ellen Gross AKA Effie Rover
The email address above goes straight to /dev/null :-)
effie -at- effierover -dot- com * http://www -dot- effierover -dot- com
Effie Rover's Fantasy Role Playing Gamer's Library


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

Date: Fri, 26 Feb 1999 00:32:46 GMT
From: null@effierover.com (Effie Rover)
Subject: Re: Q: Why is this array not defined outside the subroutine?
Message-Id: <36d7eafb.296566582@news.iinc.com>

On 25 Feb 1999 19:19:20 -0500, Jonathan Feinberg <jdf@pobox.com>
wrote:

>null@effierover.com (Effie Rover) writes:
>
>> When I reference the arrays after leaving this routine, they're
>> empty???
>
>>       push @CONTLIST, "${pathN},${branch}";                   
>>       push @CONTTITLELIST, "${pathT},$CONT[$branch]";         
>>     push @MATCHINGSITELIST, $pathN;                           
>
>If this routine is in package Foo and you're calling it from package
>main (or whatever) then those globals (which are really @Foo::CONTLIST
>etc.) won't be defined in main.  I'm *guessing* that's the source of
>your problem.  You may wish to either export those variables from Foo
>or refer to them explicitly (@Foo::WHATEVER) from main.

Thanks much, but no packages whatsoever. It's 96 lines of real simple
flat text file parsing. Took a moment just now to firm up definitions
on the arrays, but they still do exist inside and don't exist outside.
(before someone points it out, my debug code prints the variables
pushed onto the array, not the array itself - but I've done that too
to be absolutely certain the arrays are getting the data. They are.)

I'm confused %:-/

  -- Loy

Loy Ellen Gross AKA Effie Rover
The email address above goes straight to /dev/null :-)
effie -at- effierover -dot- com * http://www -dot- effierover -dot- com
Effie Rover's Fantasy Role Playing Gamer's Library


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

Date: 25 Feb 1999 22:48:31 -0500
From: Jonathan Feinberg <jdf@pobox.com>
To: effie@effierover.com (Effie Rover)
Subject: Re: Q: Why is this array not defined outside the subroutine?
Message-Id: <m33e3tu8og.fsf@joshua.panix.com>

null@effierover.com (Effie Rover) writes:

> It's 96 lines of real simple flat text file parsing.

Can you make a *shorter* complete example that exhibits the same
behavior and post it here?

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


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

Date: Fri, 26 Feb 1999 14:51:51 GMT
From: null@effierover.com (Effie Rover)
Subject: Re: Q: Why is this array not defined outside the subroutine?
Message-Id: <36d6b408.348043806@news.iinc.com>

On 25 Feb 1999 22:48:31 -0500, Jonathan Feinberg <jdf@pobox.com>
wrote:

>Can you make a *shorter* complete example that exhibits the same
>behavior and post it here?

[sheepish look] I found my problem. The program is not completing in
time and the Apache server is cutting it off. So it's getting through
long enough to give me answers, then timing out. Since I'm testing
results by web, I'm not seeing that. [shakes head] Guess I should
learn to test from the command line more ... at any rate a shorter
dataset or longer timeout is giving me the proper results.

Thanks to everyone who posted ... after staring at it for weeks, your
comments gave me fresh perspective to be able to see this.

  -- Loy

Loy Ellen Gross AKA Effie Rover
The email address above goes straight to /dev/null :-)
effie -at- effierover -dot- com * http://www -dot- effierover -dot- com
Effie Rover's Fantasy Role Playing Gamer's Library


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

Date: 23 Feb 1999 10:53:02 -0800
From: Kin Cho <kin@symmetrycomm.com>
Subject: randomize sequence
Message-Id: <u1zjhne9d.fsf@symmetrycomm.com>

I need an efficient function to randomize a sequence of
numbers in the range 1..n.  For example:

@s = randomize(1..3);  # @s now contains 1, 2, and 3, but in random order

Thanks!

-kin



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

Date: Tue, 23 Feb 1999 15:21:28 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: kin@symmetrycomm.com
Subject: Re: randomize sequence
Message-Id: <36D30DC8.1F14A161@giss.nasa.gov>

[courtesy copy sent to Kin]

Kin Cho wrote:
> 
> I need an efficient function to randomize a sequence of
> numbers in the range 1..n.  For example:

this is FAQ 4.48, recently posted by Tom Christiansen:

on 22 Feb 1999 11:12:30, in 36d19e0e@csnews, Tom Christiansen wrote:
> 
>   How do I permute N elements of a list?
> 
>     Here's a little program that generates all permutations of all the words
>     on each line of input. The algorithm embodied in the permute() function
>     should work on any list:
> 
>         #!/usr/bin/perl -n
>         # tsc-permute: permute each word of input
>         permute([split], []);
>         sub permute {
>             my @items = @{ $_[0] };
>             my @perms = @{ $_[1] };
>             unless (@items) {
>                 print "@perms\n";
>             } else {
>                 my(@newitems,@newperms,$i);
>                 foreach $i (0 .. $#items) {
>                     @newitems = @items;
>                     @newperms = @perms;
>                     unshift(@newperms, splice(@newitems, $i, 1));
>                     permute([@newitems], [@newperms]);
>                 }
>             }
>         }

--  
	"Don't be too proud of this technological
	 terror you've constructed."
        -- Darth Vader


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

Date: 23 Feb 1999 13:23:58 -0800
From: Kin Cho <kin@symmetrycomm.com>
Subject: Re: randomize sequence
Message-Id: <uyalon79t.fsf@symmetrycomm.com>

permute isn't doing what I want, I think.
Here's a version that illustrate what I need:

# perform @_ random exchanges on @_
sub shuffle {
   my @n = @_;
   for (1..@n) {
      my $i = rand(@n);
      my $j = rand(@n);
      my $t = $n[$i];
      $n[$i] = $n[$j];
      $n[$j] = $t;
   }
   return @n;
}

Is there a more efficient way?

-kin

>>>>> "Jay" == Jay Glascoe <jglascoe@giss.nasa.gov> writes:

 Jay> [courtesy copy sent to Kin]
 Jay> Kin Cho wrote:
 >> 
 >> I need an efficient function to randomize a sequence of
 >> numbers in the range 1..n.  For example:

 Jay> this is FAQ 4.48, recently posted by Tom Christiansen:

 Jay> on 22 Feb 1999 11:12:30, in 36d19e0e@csnews, Tom Christiansen wrote:
 >> 
 >> How do I permute N elements of a list?
 >> 
 >> Here's a little program that generates all permutations of all the words
 >> on each line of input. The algorithm embodied in the permute() function
 >> should work on any list:
 >> 
 >> #!/usr/bin/perl -n
 >> # tsc-permute: permute each word of input
 >> permute([split], []);
 >> sub permute {
 >> my @items = @{ $_[0] };
 >> my @perms = @{ $_[1] };
 >> unless (@items) {
 >> print "@perms\n";
 >> } else {
 >> my(@newitems,@newperms,$i);
 >> foreach $i (0 .. $#items) {
 >> @newitems = @items;
 >> @newperms = @perms;
 >> unshift(@newperms, splice(@newitems, $i, 1));
 >> permute([@newitems], [@newperms]);
 >> }
 >> }
 >> }

 Jay> --  
 Jay> 	"Don't be too proud of this technological
 Jay> 	 terror you've constructed."
 Jay>         -- Darth Vader


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

Date: Tue, 23 Feb 1999 18:20:22 -0500
From: "Allan M. Due" <Allan@Due.net>
Subject: Re: randomize sequence
Message-Id: <pJGA2.569$986.11800@nntp1.nac.net>

Kin Cho wrote in message ...
:permute isn't doing what I want, I think.
:Here's a version that illustrate what I need:
:
:# perform @_ random exchanges on @_
:sub shuffle {
:   my @n = @_;
:   for (1..@n) {
:      my $i = rand(@n);
:      my $j = rand(@n);
:      my $t = $n[$i];
:      $n[$i] = $n[$j];
:      $n[$j] = $t;
:   }
:   return @n;
:}


Yesterday Tom C posted the FAQ that covers this.  FAQ 4.45: How do I shuffle
an array randomly?   All you should need to do is scroll down in your
newsreader, or search for the subject line (given above) in dejanews.

HTH

AmD
--
$email{'Allan M. Due'} =' Allan@Due.net '
--random quote--
Algren's Precepts:
Never eat at a place called Mom's. Never play cards with a man
named Doc. And never lie down with a woman who's got more troubles
than you.





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

Date: Tue, 23 Feb 1999 18:25:45 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: kin@symmetrycomm.com
Subject: Re: randomize sequence
Message-Id: <36D338F9.BADA3B6C@giss.nasa.gov>

Kin Cho wrote:
> 
> permute isn't doing what I want, I think.
> Here's a version that illustrate what I need:
> 

whoops!  <blush> I gave you the wrong the FAQ!
Here's perlfaq4 "How do I shuffle an array randomly?":

# fisher_yates_shuffle( \@array ) :
# generate a random permutation of @array in place
sub fisher_yates_shuffle {
    my $array = shift;
    my $i;
    for ($i = @$array; --$i; ) {
        my $j = int rand ($i+1);
        next if $i == $j;
        @$array[$i,$j] = @$array[$j,$i];
    }
}

fisher_yates_shuffle( \@array );    # permutes @array in place

--  
Q: "are variables local by default when used in a foreach loop?"
A: "Yes, sometimes, if there's no lexical in scope.
    But then it's a local, which is really a global.
    This is all explained in the perlsyn manpage."

	-- Tom Christiansen, in 36c9b5d3@csnews


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

Date: 24 Feb 1999 01:07:14 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: randomize sequence
Message-Id: <7avjc2$ao5$6@client2.news.psi.net>

Jay Glascoe (jglascoe@giss.nasa.gov) wrote on MMII September MCMXCIII in
<URL:news:36D30DC8.1F14A161@giss.nasa.gov>:
|| [courtesy copy sent to Kin]
|| 
|| Kin Cho wrote:
|| > 
|| > I need an efficient function to randomize a sequence of
|| > numbers in the range 1..n.  For example:
|| 
|| this is FAQ 4.48, recently posted by Tom Christiansen:
|| 
|| on 22 Feb 1999 11:12:30, in 36d19e0e@csnews, Tom Christiansen wrote:
|| > 
|| >   How do I permute N elements of a list?


That's something else.


See Algorithms::Numerical::Shuffle on CPAN.




Abigail
-- 
perl -we 'print split /(?=(.*))/s => "Just another Perl Hacker\n";'


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

Date: Wed, 24 Feb 1999 14:32:49 GMT
From: alany@2021.com (Alan Young)
Subject: Re: Re: Can perl do this?
Message-Id: <36d60cf1.3512800@news.supernews.com>

[cc'd tchrist@mox.perl.com (Tom Christiansen)]

On 23 Feb 1999 19:56:12 -0700, Tom Christiansen <tchrist@mox.perl.com>
wrote:

>Another one?  I answer this question every day!  Why why why?

</lurk>

I've noticed that you tend to do that.

Why not ignore them, especially now that you've started posting FAQ
snippets?  Which, BTW, I appreciate.

<lurk>

-- 
Alan Young                                            Technical Support
http://members.xoom.com/AlanYoung                 2021.Interactive, LLC
If your happy and you know it, clunk your chains!   http://www.2021.com

515 A sucking chest wound is just nature's way of telling you to slow 
down.



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

Date: Wed, 24 Feb 1999 15:42:16 -0500
From: Mimi Cummins <mimi@lino.com>
Subject: reading form data
Message-Id: <36D46428.9F7B2579@lino.com>

Hello all,

I have a script set up for adding recipes to my site.  The script will
take form data and convert that data into a html file.  The problem
I'm having is that I have to input the recipe text into a textarea
box.  When I input the recipe, it looks like this:

	1 cup flour
	1 cup sugar
	1 egg

	Mix together and bake at 350 F.

However, when my script creates the html file, the recipe looks like
this:

	1 cup flour 1 cup sugar 1 cup egg

	Mix together and bake at 350 F.

and the html generated by the script looks like this:

	 <P>
        <font size=+1><b>
        <!--title--> Recipe Name
        </b></font>
        <P>
         <i>By Mimi</i><br>
         <!--date--> 2/24/99
         <P> 1 cup flour 1 cup sugar 1 egg<P>Mix together and bake at
350 F. <P>
            
        <a href="../../index1.shtml">Return to front page</a>
        <P>

As you can see, the script isn't inserting a line break after each
item in the ingredient list, but it IS inserting a <P> between the
ingredient list and the directions.  From what I understand, the
script first creates an URL out of the form data, which looks like
this:
http://www.vegetablepatch.net/cgi-bin/addcontent.cgi?type=Breakfast&new_type=&topic=Meatless&new_topic=&title=Recipe+Name&author=Mimi&date=2%2F24%2F99&article=1+cup+flour%0D%0A1+cup+sugar%0D%0A1+egg%0D%0A%0D%0AMix+together+and+bake+at+350+F.

Then it decodes the URL and turns it into an .html file.  That part of
the script is here:

#read form data
sub getFormData {
    my($hashRef) = shift;
    my($buffer) = "";
    
    if ($ENV{'REQUEST_METHOD'} eq "GET") {
	$buffer = $ENV{'QUERY_STRING'};
    }
    else {
	read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
    }

    foreach (split(/&/, $buffer)) {
	my($key, $value) = split(/=/, $_);
	$key = decodeURL($key);
	$value = decodeURL($value);
	$value =~ s/(<P>\s*)+/<P>/ig;
	$value =~ s!\cM!!g;
	$value =~ s!\n\n!<P>!g;
	$value =~ s!\n! !g;

	%{$hashRef}->{$key} = $value;
    }
    
    $fields{'article'} =~ s!\cM!!g;
    $fields{'article'} =~ s!\n\n!<P>!g;
    $fields{'article'} =~ s!\n!<BR>!g;
}

sub decodeURL {
    $_ = shift;
    tr/+/ /;
    s/%(..)/pack('c', hex($1))/eg;
    return($_);
}

sub saveFormData {
    my($hashRef) = shift;
    my($file)   = shift;
    open(FILE, ">$file");
    print FILE ("$hashRef->{'type'}~");
    print FILE ("$hashRef->{'new_type'}~");
    print FILE ("$hashRef->{'topic'}~");
    print FILE ("$hashRef->{'new_topic'}~");
    print FILE ("$hashRef->{'title'}~");
    print FILE ("$hashRef->{'author'}~");
    print FILE ("$hashRef->{'date'}~");
    print FILE ("$hashRef->{'article'}~");
    print FILE ("\n");
    close(FILE);
}

sub readFormData {
    my($file) = shift;
    open(FILE, "<$file");

#get variables from data file
    while (<FILE>) {
	($type, $new_type, $topic, $new_topic, 
	$title, $author, $date, $article) = split(/~/, $_);
	close(FILE);
    }

#make $new_type unix filename-compliant by stripping 
#whitespace and non-word chars
    if ($new_type eq "") {
	0;
    } else {
	$new_type_clean = $new_type;
	$new_type_clean =~ s!\s!!g;
	$new_type_clean =~ s!\W!!g;
#add new type to list of topics for front page
	open(FILE, ">>includes/areas.html");
	print FILE ("<option value=\"$new_type_clean\">
	$new_type\n");
	close(FILE);
	$type = $new_type_clean;
    }

#make sure directory doesn't already exist, then create it
    if (-d "$type") {
	0;
    } else {
    `mkdir $type`;
    }

#make $new_topic unix filename-compliant by stripping 
#whitespace and non-word chars
    if ($new_topic eq "") {
	0;
    } else {
	$new_topic_clean = $new_topic;
	$new_topic_clean =~ s!\s!!g;
	$new_topic_clean =~ s!\W!!g;
#add new topic to list of topics for front page
	open(FILE, ">>includes/topics.html");
	print FILE ("<option value=\"$new_topic_clean\">
	$new_topic\n");
	close(FILE);
	$topic = $new_topic_clean;
    }

#make sure directory doesn't already exist, then create it
    if (-d "$type/$topic") {
	0;
    } else {
    `mkdir $type/$topic`;
    }

#find out how many articles are in folder, and give new article
#a filename which equals the number of articles + 1
    @filelist = `ls $type/$topic`;
    $filename = $#filelist + 1;

#create new file
    open(TMP, ">$type/$topic/$filename.html");
    print TMP qq(
        <!--\#include virtual=\"../../includes/header.txt\" -->
        <P>
        <font size=+1><b>
        <!--title--> $title
        </b></font>
        <P>
         <i>By $author</i><br>
         <!--date--> $date
         <P> $article <P>
            
        <a href="../../index.html">Return to front page</a>
        <P>
        <!--\#include virtual=\"../../includes/footer.txt\" -->
                   );
    close(TMP);
    
}


Does anyone out there have enough Perl know-how to modify my script to
make it insert a <BR> after each item in the ingredient list?  I would
be eternally grateful.  :o)

Mimi


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

Date: Thu, 25 Feb 1999 01:05:10 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: reading form data
Message-Id: <slrn7d98h2.5o.alastair@calliope.demon.co.uk>

Mimi Cummins <mimi@lino.com> wrote:
>#get variables from data file
>    while (<FILE>) {
>	($type, $new_type, $topic, $new_topic, 
>	$title, $author, $date, $article) = split(/~/, $_);
>	close(FILE);
>    }

Hi,

I have to admit that I found the code a little difficult to wade through but I
persisted (a bit). I'm used to using the CGI module - which makes things a lot
easier. It might be worth checking into ;

You can find CGI.pm here ;

http://stein.cshl.org/~lstein/

As for your script, I think you only need to replace carriage returns with
'<BR>' tags before printing eg.

Just before the file close above ;

$article =~ s/\n/<BR>/g;

I mightbe making assumptions about your line break's though.

You could also get round this by wrapping $article in <PRE></PRE> tags. Not
quite so pleasing but effective i.e.

<PRE>
$article
</PRE>

HTH.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Wed, 24 Feb 1999 14:49:01 GMT
From: David Sloan <ceedas@cee.hw.ac.uk>
Subject: Reading from files
Message-Id: <Pine.SUN.3.95.990224144502.5910C-100000@bes>

Is there an easy way to read a single line from a file, without using
a while loop. Let me illustrate:

I want to read in the first line of a file, perform some pattern
matching operations on it, get a substring and then find the next line
containing this substring.

Do I need another while for this too? If you can help, an email would
be  appreciated.

Thanks
Dave

--------------------------------
David Sloan
Heriot-Watt University
Edinburgh



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

Date: Wed, 24 Feb 1999 13:41:23 -0500
From: Jay Glascoe <jglascoe@giss.nasa.gov>
To: David Sloan <ceedas@cee.hw.ac.uk>
Subject: Re: Reading from files
Message-Id: <36D447D3.BC1C1EE6@giss.nasa.gov>

[courtesy copy of post sent to David via email]

David Sloan wrote:
> 
> Is there an easy way to read a single line from a file, without using
> a while loop. Let me illustrate:
> 
> I want to read in the first line of a file, perform some pattern
> matching operations on it, get a substring and then find the next line
> containing this substring.

my $first_line = <FH>;
# do stuff with first line
while my $line (<FH>) {
    # do something with $line
    break if i_dont_like($line);
}

or

my $first_line = <FH>;
my @other_lines = <FH>;

--  
"'C' is for 'Cookie'.  That's good enough for me."
	--Cookie Monster


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

Date: Wed, 24 Feb 1999 12:27:03 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Reading from files
Message-Id: <MPG.113e007014b2cc25989685@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <36D447D3.BC1C1EE6@giss.nasa.gov> on Wed, 24 Feb 1999 
13:41:23 -0500, Jay Glascoe <jglascoe@giss.nasa.gov> says...
> [courtesy copy of post sent to David via email]
 ...
> my $first_line = <FH>;
> # do stuff with first line
> while my $line (<FH>) {
>     # do something with $line
>     break if i_dont_like($line);
> }

You write too much C code.  In Perl, 'break' is spelled 'last' (and 
'continue'is spelled 'next', in case that's what you meant).

-- 
Larry Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Thu, 25 Feb 1999 19:39:25 -1000
From: "Jack Guyant" <jackg@aloha.net>
Subject: Re: Reading from files
Message-Id: <7b5c0d$b0e$1@nuhou.aloha.net>

If the file's not too large, you could try "reading" the file into an
array--rather than a scalar (as you would for a single line). Then you
could, of course, either process the array or convert the array's contents
into a scalar.




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

Date: Tue, 23 Feb 1999 16:27:35 -0600
From: "Wade T. Funk" <wfunk@dev.tivoli.com>
Subject: Reading/Writing from/to a process....
Message-Id: <36D32B57.9D8CB64F@dev.tivoli.com>

Anyone have any ideas on how I would read/write from/to a process
that has been spawned in the background in a perl script?

Thanks,
-- 
Wade T. Funk
Systems Administrator
Tivoli Systems, Inc.
(512) 436-8302


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

Date: 24 Feb 1999 00:57:09 GMT
From: mjtg@cus.cam.ac.uk (M.J.T. Guy)
Subject: Re: Reading/Writing from/to a process....
Message-Id: <7avip5$ci4$1@pegasus.csx.cam.ac.uk>

Wade T. Funk <wfunk@dev.tivoli.com> wrote:
>Anyone have any ideas on how I would read/write from/to a process
>that has been spawned in the background in a perl script?

perldoc perlipc   has a number of suggestions.


Mike Guy


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

Date: Wed, 24 Feb 1999 00:59:13 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: Reading/Writing from/to a process....
Message-Id: <slrn7d6jps.5h.alastair@calliope.demon.co.uk>

Wade T. Funk <wfunk@dev.tivoli.com> wrote:
>Anyone have any ideas on how I would read/write from/to a process
>that has been spawned in the background in a perl script?

Yes. This is covered as a FAQ - try perlfaq8.

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: 24 Feb 1999 12:47:53 +0100
From: Tony Curtis <Tony.Curtis+usenet@vcpc.univie.ac.at>
Subject: Re: Reading/Writing from/to a process....
Message-Id: <8390do9g5y.fsf@vcpc.univie.ac.at>

Re: Reading/Writing from/to a process...., Wade
<wfunk@dev.tivoli.com> said:

Wade> Anyone have any ideas on how I would
Wade> read/write from/to a process that has been
Wade> spawned in the background in a perl script?

perldoc perlipc

hth
tony
-- 
Tony Curtis, Systems Manager, VCPC,    | Tel +43 1 310 93 96 - 12; Fax - 13
Liechtensteinstrasse 22, A-1090 Wien.  | <URI:http://www.vcpc.univie.ac.at/>
"You see? You see? Your stupid minds!  | private email:
    Stupid! Stupid!" ~ Eros, Plan9 fOS.| <URI:mailto:tony_curtis32@hotmail.com>


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

Date: Sun, 21 Feb 1999 23:11:25 -0600
From: Matt Steven <nospam@geniusweb.com>
Subject: Re: ReadParse confusion
Message-Id: <36D0E6FC.313E6BA@geniusweb.com>


Curtiss Hammock wrote:

> I admit it, I'm a novice at this.  I'm trying to take a Username from
> an HTML form and redirect to a specific web page with PERL.

Ok, what's returned from ReadParse is a hash of all form elements.

>  <form action="/cgi-bin/user.pl">
>   <p><input type="Text" name="username" size="20" maxlength="15"></p>
>   </form>
>

So from this form if you have an input called "username"

if(&ReadParse(*IN);){
    print "Location: http://the.web.site/$IN{'username'}/index.html\n\n";
}

This way you don't have to make a fresh line of code for each potential
username either.  'Corse they get a 404 if they mistype, but you can check
ahead of time with -e.

--
Matthew Steven
Freelance Web Developer
And Linux Hobbyist
http://GeniusWeb.com/
PERL * C * HTML * JavaScript * You name it...




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

Date: 23 Feb 1999 13:06:12 -0600
From: Dale Henderson <dhenders@cpsgroup.com>
Subject: Re: Real-time Browser Updating
Message-Id: <87zp659byz.fsf@camel.cpsgroup.com>

>>>>> "Ala" == Ala Qumsieh <aqumsieh@matrox.com> writes:

    Ala> Dale Henderson <dhenders@cpsgroup.com> writes:

    >> You can tell it to autoflush after a print by setting $| to a
    >> non-zero value (i.e. put $|=0 at the begining of the program.)

    Ala> I don't think 0 is a non-zero value ;-)

    Ala> Ala

Oops I think i meant $|=1.

-- 
Dale Henderson <mailto:dhenders@cpsgroup.com> 

"Imaginary universes are so much more beautiful than this stupidly-
constructed 'real' one..."  -- G. H. Hardy


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

Date: 12 Dec 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 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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

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