[9612] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3206 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Jul 20 15:17:29 1998

Date: Mon, 20 Jul 98 12:00:28 -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           Mon, 20 Jul 1998     Volume: 8 Number: 3206

Today's topics:
    Re: Array element translation (Craig Berry)
        beginner: better code for word separation combinations (Ralph Brands)
    Re: CGI: how to force Netscape to show results line by  fascist@posix.org
    Re: CGI: how to force Netscape to show results line by  (Steve Linberg)
    Re: compare arrays <jhi@alpha.hut.fi>
        filename array <mikehoyt@compassnet.com>
    Re: Grepping/Comparing two-dimentional arrays? <jdporter@min.net>
        how to pass by reference <nonspammers.cut.after.the.period.hot_redox@hotmail.com>
    Re: need help: open file for write <quednauf@nortel.co.uk>
    Re: OOP : Object Oriented PROBLEMS! <zenin@bawdycaste.org>
        Overriding builtin functions <yary@apicom.com>
    Re: Overriding builtin functions <yary@apicom.com>
    Re: Perl commands in NT Q's:  (was Re: Win32 install pr <nonspammers.cut.after.the.period.hot_redox@hotmail.com>
    Re: PS1 update from a background script (Matt Knecht)
    Re: Regex: operand could be empty (Craig Berry)
    Re: Regex: operand could be empty (Craig Berry)
    Re: Reverse an associative array (William Wueppelmann)
        Turning 13 lines of text into one <larryq@nospam.tuttle.com>
    Re: Turning 13 lines of text into one (Larry Rosler)
    Re: Turning 13 lines of text into one <minich@globalnet.co.uk>
    Re: Web Components birgitt@my-dejanews.com
    Re: Wierd behaviour of .. operator (Larry Rosler)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 20 Jul 1998 18:31:46 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Array element translation
Message-Id: <6p02ei$fgs$3@marina.cinenet.net>

Joseph June (jjune@midway.uchicago.edu) wrote:
: I have an array with numbers from 0 - 3.  I want to create another array
: from the previous array... with a conversion... all of previous 0s should
: be 3s and 1s should be 2s.. so 
: 
: How can I convert 
: 
: 012121 to 321212

  @xformed = map { abs ($_ - 3) } @original;

: I've tried
: 
: (@seq = @comp) =~ tr/0123/3210/
: 
: but doesn't seem to work..

You can't apply tr to a list, has to be a scalar.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: Mon, 20 Jul 1998 11:55:23 -0200
From: brinton@unixg.ubc.ca (Ralph Brands)
Subject: beginner: better code for word separation combinations
Message-Id: <brinton-2007981155240001@ppp64.whidbey.com>

I have a program that searches for examples of a first word followed by a
second word in text.

If the program finds a section of text with more than one example of one
or both words, I want to indicate the number of words between the first
and second search words in all possible combinations of those words. 

For example, if "cat" is the first search word and "dog" is the second
search word, I want to do this: 

$matchstring = There is a cat and cat but also a dog and the another cat
and dog and cat in this sentence.

words that are cat:
4
6
14
18

words that are dog:
10
16


For each dogvalue
For each catvalue
    if dogvalue > catvalue
   wordseparationvalue = dogvalue - catvalue + 1
->
   
3, 5
1, 9, 11


When I first made this program, I came up with the hideous solution below,
which definitely works, but I'd like to clean things up. Can someone
please suggest how to implement this as economically as possible? Many
thanks,

John Crichton.

   


HORRIBLE WAY TO DO IT:
   
sub ambiguous  {

if ($matchstring =~/$var3.*$var4/gi)  {
@matchstring = split(/[\t ]+/, $matchstring);

for (@matchstring) {
             if($matchstring[0] =~ /$var3/gi)  {
                  $amatch = join(" ",@matchstring);
                  push(@searcharray1, $amatch);
                  }

             shift(@matchstring);

             if($matchstring[0] =~ /$var3/gi)  {
                  $amatch = join(" ",@matchstring);
                  push(@searcharray1, $amatch);
                  }
}
}

for (@searcharray1)  {
        @searcharray2sub = split(/[\t ]+/, $_);
        @searcharray3sub = reverse(@searcharray2sub);
        $searchlist3 = join(" ", @searcharray3sub);
        push(@searcharray2, $searchlist3);
        }

$searcharray2 = @searcharray2;

for (@searcharray2) {
     @matchstring2 = split(/[\t ]+/, $_);
     for (@matchstring2)  {
             if($matchstring2[0] =~ /$var4/gi)  {
                  $amatch2 = join(" ",@matchstring2);
                  push(@searcharray3, $amatch2);
                  }

             shift(@matchstring2);

             if($matchstring2[0] =~ /$var4/gi)  {
                  $amatch2 = join(" ",@matchstring2);
                  push(@searcharray3, $amatch2);
                  }
}
}

for (@searcharray3)  {
             @matchstring3 = split(/[\t ]+/, $_);
             @searcharray4sub = reverse(@matchstring3);
             $searchlist4 = join(" ", @searcharray4sub);
             push(@searcharray4, $searchlist4);
}

$searcharray4 = @searcharray4;
for ($i = 0; $i <= ($searcharray4-1); $i++)  {
        @searcharray4sub = split(/[\t ]+/, $searcharray4[$i]);
        $searcharray4sub = @searcharray4sub;
        $wordsep = $searcharray4sub-2;
        push(@wordsep, $wordsep);
        if (eval($sepcondition))  {  $ambiguousmatch=1;  }
        }

$wordsep = join(" ", @wordsep);     #to print in output

}


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

Date: 20 Jul 1998 18:14:10 GMT
From: fascist@posix.org
Subject: Re: CGI: how to force Netscape to show results line by line?
Message-Id: <6p01di$943$1@eve.enteract.com>


make the name of the script be "nph-whatever".

Alex Dong Li <ali@genet.sickkids.on.ca> wrote:
> Hello, CGI experts,

> I have written a CGI script to run another, big script.
> This big script will print out some message to the web client during the 
> process. My question is: how to force Netscape to show the results line by 
> line, instead of showing the whole results at the end of big script 
> processing?

> For the following simple example, the netscape will not show anything until 
> 10 seconds later, when the program ends (I want Netscape to print out 
> counters one by one, during script processing):

> print &PrintHeader;
> print "<html><body>\n";
> for ($count=0; $count<10; $count++) {
>    print "$count\n";
>    sleep (1);
> }
> print "</body></html>\n";

> Regards,

> Alex


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

Date: Mon, 20 Jul 1998 14:38:49 -0400
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: CGI: how to force Netscape to show results line by line?
Message-Id: <linberg-2007981438490001@projdirc.literacy.upenn.edu>

In article <6ovnb4$947$1@resunix.sickkids.on.ca>, ali@genet.sickkids.on.ca
(Alex Dong Li) wrote:

> Hello, CGI experts,

Wrong group.  The CGI experts are in comp.infosystems.www.authoring.cgi. 
Followups set.
_____________________________________________________________________
Steve Linberg                       National Center on Adult Literacy
Systems Programmer &c.                     University of Pennsylvania
linberg@literacy.upenn.edu              http://www.literacyonline.org


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

Date: 20 Jul 1998 21:41:19 +0300
From: Jarkko Hietaniemi <jhi@alpha.hut.fi>
Subject: Re: compare arrays
Message-Id: <oeevhosicvk.fsf@alpha.hut.fi>


domo@tcp.ip.lu (Dominic Dunlop) writes:

> 
> Stale thread, but WTH, I'll jump in anyway...
> 
> Craig Berry <cberry@cinenet.net> wrote in respose to a question from
> Alberto Brosich <brosich@univ.trieste.it>:
> > 
> > : How can i compare two arrays other then with a loop?
> > 
> > Short answer: You can't do it without looping.
> 
> Umm, yes you can.  For a straight equality check of two arrays, @x and
> @y, 
> 
>         "@x" eq "@y"
> 
> works fine -- provided that you consider the two arrays to be equal if

*Assuming* your array elements do not contain the $", the default of
which is " ".  @x=("foo bar");@y=("foo", " bar");

One should also remember the fast test for the sizes of the arrays:
@x == @y.  If this is not true, the arrays cannot be equal.

-- 
$jhi++; # http://www.iki.fi/~jhi/
        # There is this special biologist word we use for 'stable'.
        # It is 'dead'. -- Jack Cohen


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

Date: Mon, 20 Jul 1998 18:51:01 GMT
From: mikehoyt <mikehoyt@compassnet.com>
Subject: filename array
Message-Id: <35B391A7.6D710948@compassnet.com>

Sorry I'm a newbie.  Actually this is my first real program.  I'm trying
to make a crude search engine for a web site, and I need to know how to
make an array out of every .htm file in the directory.



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

Date: Mon, 20 Jul 1998 17:54:40 GMT
From: John Porter <jdporter@min.net>
Subject: Re: Grepping/Comparing two-dimentional arrays?
Message-Id: <35B385E2.1B76@min.net>

Brian Reilly wrote:
> 
> Hi all, I'm trying to compare an item [x,3] in two two-dimensional arrays,
> to see if there are any intersections or new items.

Can I make a few suggestings which might make your life a little easier?


> $old = `cat data.old`;
> $data = `cat data`;

Looks like you're slurping the entire output as one string, then
splitting on newlines.  Since you're doing that, you can skip
the explicit split, by letting $\ have its default value, and
reading directly into an array.

And what's with `cat`?  Is open() not good enough for you?

        $f = 'data';
	open(F,"< $f") or die "open $f: $!";
	@list = <F>;
	close(F);

        $f = 'data.old';
	open(F,"< $f") or die "open $f: $!";
	@oldlist = <F>;
	close(F);


> foreach $oldie (@oldlist)
>         {
>         @tmp2  = split (/,/, $oldie);
>         push @olduser, [ @tmp2 ];
>         }

Um, [ @tmp2 ] makes an unnecessary copy of @tmp2....
Unnecessary, that is, if @tmp2 is properly 'my'd:

	for ( @oldlist ) {
		my @tmp = split ',';
		push @olduser, \@tmp;
	}

Even simpler:

	for ( @oldlist ) {
		push @olduser, [ split ',' ];
	}

Simpler still:

	@olduser = map { [ split ',' ] } @oldlist;

The effect is the same (except it blows away any prior
contents of @olduser, which I think is o.k., in this case).

Now, combine that with the open/read part:

	$f = 'data.old';
	open(F,"< $f") or die "open $f: $!";
	@olduser = map { [ split ',' ] } <F>;
	close(F);


> ###Will print all of the elements#####
> for $i ( 0 .. $#user )
>       {
>       $aref = $user[$i];
>       $n = @$aref - 1;

Um, don't do that.  You can use $# on array refs too:

	$n = $#{$aref};

>       for $j ( 0 .. $n)
>               {
>               print "elt $i $j is $user[$i][$j]\n";
>               }
>       }

Now, of course, you don't need all those temporaries.

for $i ( 0 .. $#user ) {
	for $j ( 0 .. $#{$user[$i]} ) {
              print "elt $i $j is $user[$i][$j]\n";
	}
}


You said you wanted to compare the [x,3] slice of each
array.  Since you already know how to compare 1-d arrays,
you just need a way to get the [x,3] row out of each 2-d
array into a 1-d array.  Here's how:

	@old3 = map { $_->[3] } @olduser;

-- 
John Porter


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

Date: 20 Jul 1998 18:35:36 GMT
From: "Sabre Taylor" <nonspammers.cut.after.the.period.hot_redox@hotmail.com>
Subject: how to pass by reference
Message-Id: <01bdb40d$2bbb1f60$c1620c8a@lnxcompaq.lexis-nexis.com>

Hi,

	I'd like to alter subroutine parameters without using the return function.
I've tried the relevent resources, but haven't understood a simple way to
do this.

	Something similar to the C++ pass by reference is what I'm looking for.
Any help would be appreciated.

	Right now I'm relegated to using global variables, and kludging my code.


Sabre

nonspammers.start.after.this.period.hot_redox@hotmail.com



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

Date: Mon, 20 Jul 1998 17:59:48 +0100
From: "F.Quednau" <quednauf@nortel.co.uk>
Subject: Re: need help: open file for write
Message-Id: <35B37784.95397955@nortel.co.uk>

lindali@my-dejanews.com wrote:
> 
> i've consulted all the faqs and the camel book several times
> and it seems that my code is _supposed_ to be working.
> however, it's not, so any help from anyone would be appreciated!
> 
> i'm trying to open 5 files for my script to write the output
> of the data being processed.  at the command line, i am typing the
> following:
> 
>     prompt% es_prod.pl es071798.lst
> 
> so, es071798.lst is the dataset file being inputted.
> 
> the output file names must correspond to the input filename,
> i.e. i want 5 files:  es0717_h.txt, es0717_f.txt, es0717_m.txt,
> es0717_1.txt, es0717_2.txt
> 
> here is a portion of my code:
> 
[...code...]

> after the script is done running, none of the 5 output files
> are present in the current directory.
> 
> instead, the only text file there is
>     .txt
> which contains
> " The stuff i want to print to the 2 file "

When I tried your code, it wouldn't produce any file at all. Oops, sorry
it did, yes. I didn't see it as a dotted file! First of all, have you
checked that ARGV indeed holds something?
Secondly, it seems that Perl thinks that, say, $esMMDD_h is a variable.
Of course, it is undefined, which leaves .txt as being the file. Which
means that all your filehandles write to the same file, .txt, and your
last write operation is the one which gets the credit. Try the following
code, which forces $esMMDD to be used as the variable. I think there are
nicer ways to write it, though!



    $esMMDD = '/u/quednauf/temp/a_name';

    open ( ESH,  "> ${\$esMMDD}_h.txt" ) || die "Can't create h file:
$!\n";
    open ( ESF,   "> ${\$esMMDD}_f.txt" ) || die "Can't create f file:
$!\n";
    open ( ESM, "> ${\$esMMDD}_m.txt" ) || die "Can't create m file:
$!\n";
    open ( ES1, "> ${\$esMMDD}_1.txt" ) || die "Can't create 1 file:
$!\n";
    open ( ES2, "> ${\$esMMDD}_2.txt" ) || die "Can't create 2 file:
$!\n";

    # Begin parsing the input file
        print ESH " The stuff i want to print to the h file";
        print ESF " The stuff i want to print to the f file";
        print ESM " The stuff i want to print to the m file";
        print ES1 " The stuff i want to print to the 1 file";
        print ES2 " The stuff i want to print to the 2 file";


-- 
____________________________________________________________
Frank Quednau               
http://www.surrey.ac.uk/~me51fq
________________________________________________


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

Date: 20 Jul 1998 00:08:50 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: OOP : Object Oriented PROBLEMS!
Message-Id: <900893918.724935@thrush.omix.com>

[posted & mailed]

Clinton Gormley <*clinton@consol.co.uk> wrote:
	>snip<

	Just a friendly FYI.  In Usenet, it's generally considered rude
	to send a copy of a followup to the sender without some notice
	to that effect at the top of the message (as I have above).  This
	is because mail often travels faster then news, so the receiver is
	likely to have to reply twice.  Once via email, and again via news
	when the've found out you've posted the message too.

	Also, when you do send email to someone, please don't munge your
	return address.  While it can be argued as needed for posting
	to Usenet, it's just anoying when used for email.  When the
	message bounces, the person probably is just going to throw it
	away without trying to demung it.

	Just a friendly FYI.  Please don't take this as a flame.

	Thanks!

-- 
-Zenin (zenin@archive.rhps.org)           From The Blue Camel we learn:
BSD:  A psychoactive drug, popular in the 80s, probably developed at UC
Berkeley or thereabouts.  Similar in many ways to the prescription-only
medication called "System V", but infinitely more useful. (Or, at least,
more fun.)  The full chemical name is "Berkeley Standard Distribution".


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

Date: Mon, 20 Jul 1998 10:29:13 -0700
From: Yary H <yary@apicom.com>
Subject: Overriding builtin functions
Message-Id: <35B37E69.68D3@apicom.com>

Page 288 of the camel states:
"Many built-in fucntions may be *overridden*"

Many, not all.  I can't figure out what the exceptions are, or what
happens when you try to override something that may not be.

I'm asking because I'm trying to override print (on a dare). I get the
expected "Subroutine print redefined" warnings, but the redefined
subs are never called.

Here's the code, using perl 5.004_02

==vp.pm==
package vp;
use Exporter();
@ISA = ('Exporter');
@EXPORT = qw(&variable_print);

# variable print takes one arg.
# if it's undef, then restores original print
# if it's a scalar ref, then prints add to that variable.
# if it's an array ref, then prints push onto that array.
# otherwise, it's an error.
sub variable_print($) {
    my ($out) = @_;

    if (!defined $out) {
	*print = sub {CORE::print @_} }
    elsif (ref $out eq 'SCALAR') {
	*print = sub {$$out .= join($, , @_) . $\} }
    elsif (ref $out eq 'ARRAY') {
	*print = sub {push @$out, @_ } }
    else {die "Internal error: variable_print misused."}
}


==foo.pl==
#!/usr/bin/perl -w
use strict;
use vp;

variable_print(undef);
print "hello\n";

my $foo;
variable_print(\$foo);
print "my ";
print "name ";
print "is\n";

variable_print(undef);
print ("foo: $foo");


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

Date: Mon, 20 Jul 1998 11:08:19 -0700
From: Yary H <yary@apicom.com>
Subject: Re: Overriding builtin functions
Message-Id: <35B38793.3178@apicom.com>

I found bugs in the posted code, and I think I've verified that
"print" cannot be overridden.  Can it?
Also, why is it that
*{$pack.'::chdir'} = sub {CORE::print @_}
causes "chdir" to call the builtin print, but
*{$pack.'::chdir'} = *CORE::print
causes error "Undefined subroutine &CORE::print called" down the road?


==foo.pl==
#!perl -w
use strict;
use vp;

variable_chdir;
chdir "hello\n";

my $foo;
variable_chdir(\$foo);
chdir "my ";
chdir "name ";
chdir "is\n";

variable_chdir(undef);
chdir "foo: $foo";

variable_print;
print "Yary.\n";

my $bar;
variable_print(\$bar);
print "And ";
print "you ";
print "are?\n";
variable_print;
print "bar: $bar";


==vp.pm==
package vp;
use Exporter();
@ISA = ('Exporter');
@EXPORT = qw(&variable_print &variable_chdir &print &chdir);

# variable print takes one arg.
# if it's undef, then restores original print
# if it's a scalar ref, then prints add to that variable.
# if it's an array ref, then prints push onto that array.
# otherwise, it's an error.
sub variable_print(;$) {
    local $^W = 0;
    my ($out) = @_;
    my ($pack) = caller;

    if (!defined $out) {
	*{$pack.'::print'} = sub {CORE::print @_} }
    elsif (ref $out eq 'SCALAR') {
	*{$pack.'::print'} = sub {local $^W = 0;$$out .= join($, , @_) . $\ }}
    elsif (ref $out eq 'ARRAY') {
	*{$pack.'::print'} = sub {push @$out, @_ } }
    else {die "Internal error: variable_print misused."}
}


sub variable_chdir(;$) {
    local $^W = 0;
    my ($out) = @_;
    my ($pack) = caller;

    if (!defined $out) {
	*{$pack.'::chdir'} = sub {CORE::print @_} }
    elsif (ref $out eq 'SCALAR') {
	*{$pack.'::chdir'} = sub {local $^W = 0;$$out .= join($, , @_) . $\ }}
    elsif (ref $out eq 'ARRAY') {
	*{$pack.'::chdir'} = sub {push @$out, @_ } }
    else {die "Internal error: variable_chdir misused."}
}


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

Date: 20 Jul 1998 18:15:32 GMT
From: "Sabre Taylor" <nonspammers.cut.after.the.period.hot_redox@hotmail.com>
Subject: Re: Perl commands in NT Q's:  (was Re: Win32 install prob--another idiot)
Message-Id: <01bdb40a$5e0b1860$c1620c8a@lnxcompaq.lexis-nexis.com>

Neal Miyake <sponge@iav.com> wrote in article
<01bdb36f$0498b3a0$680918cf@default>...

[some stuff snipped out]
> However, I do have a few more questions relating the Perl for Win32
running
> on NT and porting some unix-based script over:
>
> 2.  Is there a equivalent "date" command under NT.  I know in NT at the
> command line, you can do a "date /t" to get back the date without prompt
to
> change it, but I would like to capture the date as a string.  Tried those
> backquotes to no avail.
> 
> 3.  What about "pwd"?  Any NT command line equivalent?
>
> That's all for now.  Again, thanks Clint, and anyone else willing to help
> this somewhat lost soul.
> 
> Aloha and cheers,
> Neal Miyake (still stressing in Hawaii)

There's a boatload of Unix commands ported to win32 at
http://www.itribe.net/virtunix/.
Also you can the DJGPP compiler from http://www.gnu.org can port Unix
commands.


Sabre



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

Date: Mon, 20 Jul 1998 18:04:07 GMT
From: hex@voicenet.com (Matt Knecht)
Subject: Re: PS1 update from a background script
Message-Id: <rELs1.10$Xy4.65189@news2.voicenet.com>

MrNobody <dunna001@bama.ua.edu> wrote:
>I am writing a notify program, and the interface that I am trying to get
>is one that will drop into the background, and then alter the user's
>prompt as needed. I do NOT want to write a command shell.

Strictly speaking, this can't be done because of the way a subshell
operates.  You can't modify variables in the parent shell.  Check out
the 'comp.unix.shell' FAQ for a detailed explaination of this.
(Section 2.8 -
      How do I {set an environment variable, change directory} inside a
      program or shell script and have that change affect my current
      shell?)

>the problem is thus, how do i do the equivalent of:
>
>>PS1="foo bar baz bat bamf
>>$"
>
>from inside a program running background but tied to the correct terminal?
>I know that this is not an environment variable issue, but what is is? Is
>it possible? Any help is much appreciated.

Having said this, you can get around it.  One easy way is to have a
shell that actually executes it's PS1, not just interpretes it.
This works in bash:

export PS1='`cat /some/path/to/output`\$ '

Everytime your prompt comes up, bash will do you the favor of dumping
the contents of /some/path/to/output for you.  Your background process
only needs to modify the contents of this file.

-- 
Matt Knecht - <hex@voicenet.com>
"496620796F752063616E207265616420746869732C20796F7520686176652066
617220746F6F206D7563682074696D65206F6E20796F75722068616E6473210F"


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

Date: 20 Jul 1998 18:22:34 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regex: operand could be empty
Message-Id: <6p01ta$fgs$1@marina.cinenet.net>

dan@nospam.org wrote:
: I'm string to read in a text file, and split it into paragraphs - i.e.
: text separated by one or more blank lines.

You can do this automagically by using the special $/ = '' "paragraph
mode" on the read, then pull in text one paragraph at a time -- see
perlvar. But to address your roll-your-own attempt... 

[snip]
: Depending on the version of Perl I use, I get either of these two
: errors on: @para = split(/(^\s*$)+/mg, <IN>);
: 
: /(^\s*$)+/: regexp *+ operand could be empty at ./splitlines.pl line
: 12. 
: 
: (^\s*$)+ matches null string many times at ./splitlines.pl line 12.

Those are both saying the same thing, that your regex can match
nothingness forever.  Consider that ^ and $ are zero-width, as \s* can
also be.  Thus, the + can match emptiness infinite times.

You can get rid of the error by using /(^\s*\n)+/mg instead; replacing
the zero-width $ with the physical newline char (width one) prevents the
infinite-copies-of-nothing problem from occurring. 

Note, however, that \s will match \n, so you can actually drop the + and
get /^\s*\n/mg -- that is, start at a line beginning, then eat whitespace
as far as possible such that the last character is a newline.

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 20 Jul 1998 18:26:27 GMT
From: cberry@cinenet.net (Craig Berry)
Subject: Re: Regex: operand could be empty
Message-Id: <6p024j$fgs$2@marina.cinenet.net>

Larry Rosler (lr@hpl.hp.com) wrote:
: In article <35B36C60.B47E913@gpu.srv.ualberta.ca> on Mon, 20 Jul 1998 
: 11:12:16 -0500, Andrew Johnson <ajohnson@gpu.srv.ualberta.ca> says...
: ...
: > rather than reading in the whole file and splitting it,
: > why not just set $/ to "" as described in the perlvar 
: > manpage and read in one 'paragraph' at a time?
: 
: Surely you mean "\n\n".

No, I think you're reading perlvar exactly backwards.  From the entry on
$/:

 Note that setting it to "\n\n"  means something slightly different than
 setting it to "", if the file contains consecutive empty lines.  Setting
 it to "" will treat two or more consecutive empty lines as a single empty
 line.  Setting it to "\n\n" will blindly assume that the next input
 character belongs to the next paragraph, even if it's a newline. 

So $/ = '' is the preferred way to get "paragraph mode."

---------------------------------------------------------------------
   |   Craig Berry - cberry@cinenet.net
 --*--    Home Page: http://www.cinenet.net/users/cberry/home.html
   |      Member of The HTML Writers Guild: http://www.hwg.org/   
       "Every man and every woman is a star."


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

Date: 20 Jul 1998 17:55:40 GMT
From: william@host.ott.igs.net (William Wueppelmann)
Subject: Re: Reverse an associative array
Message-Id: <6p00as$c14$1@news.igs.net>

Clas (qmwclka@emw.ericsson.se) wrote:
: Hello!

: I am a beginner...
: My task is to reverse an associative array.

: Say I've got an array like this:

: %ages = ("Angie ", 39,
:          "Dirty ", 34,
:          "Michael ", 27,
:          "Willy ", 21 );

: How should I do to reverse this?
: So Willy will be the first name in the associative array.

I don't think that associative arrays work quite the way you're thinking. 
If you want to list the array in reverse-alplhabetical order, you might do
something like

@ages = sort {$b cmp $a} keys(%ages);

now you have an array @ages which contains all of the keys in %ages,
sorted in reverse alphabetical order, so you can print or otherwise
manipulate them. e.g.: 

foreach (@ages) { print("$_ is $ages{$_} years old.\n") }

William


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

Date: Mon, 20 Jul 1998 11:09:44 -0700
From: "Larry" <larryq@nospam.tuttle.com>
Subject: Turning 13 lines of text into one
Message-Id: <6p01b1$179$1@nnrp2.crl.com>


    Hi everyone,


            I'm just feeling my way around here, and have a little project
I'm trying to get a bead on.  I've got a text file that contains about
10,000 records in it, each record consisting of 13 lines of text, while each
line is exactly 80 characters long.  I need to take each "record", and turn
the 13 lines of text into one really long line.  What's the best way to do
so?  Thanks for any and all suggestions!






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

Date: Mon, 20 Jul 1998 11:24:12 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Turning 13 lines of text into one
Message-Id: <MPG.101d2b2ab2205dba98972a@nntp.hpl.hp.com>

In article <6p01b1$179$1@nnrp2.crl.com> on Mon, 20 Jul 1998 11:09:44 -
0700, Larry <larryq@nospam.tuttle.com> says...
 ...
> ...  I've got a text file that contains about
> 10,000 records in it, each record consisting of 13 lines of text, while each
> line is exactly 80 characters long.  I need to take each "record", and turn
> the 13 lines of text into one really long line.  What's the best way to do
> so?  Thanks for any and all suggestions!

Yet Another Larry!!!

`perldoc -f join` is what you want.  You may want to use chomp() to 
remove new-line characters before replacing them with something else 
using join().

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


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

Date: Mon, 20 Jul 1998 19:41:48 +0100
From: "Martin" <minich@globalnet.co.uk>
Subject: Re: Turning 13 lines of text into one
Message-Id: <6p02uq$mt0$1@heliodor.xara.net>

>            I'm just feeling my way around here, and have a little project
>I'm trying to get a bead on.  I've got a text file that contains about
>10,000 records in it, each record consisting of 13 lines of text, while
each
>line is exactly 80 characters long.  I need to take each "record", and turn
>the 13 lines of text into one really long line.  What's the best way to do
>so?  Thanks for any and all suggestions!


I've just spent a few weeks programming a lot of Perl and this was one of
the functions I used. I'm sure there's a much more elegant - shorter way of
doing it involving the odd / here and there; but this is what I used.

# put the filename into $filename

open(INF,"$filename");
@number = <INF>;
close(INF);

$temp="@number";
@temp2 = split(/\n/, $temp);
foreach $temp3 (@temp2) {
    $nolines = "$nolines$temp3";
}

open(INF,">$filename");
print INF "$nolines";
close(INF);



That's it! The script takes the file input, puts it all on one line, and
rewrites the old file with the new file containing only one line.

Martin




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

Date: Mon, 20 Jul 1998 18:16:45 GMT
From: birgitt@my-dejanews.com
Subject: Re: Web Components
Message-Id: <6p01id$7rb$1@nnrp1.dejanews.com>

In article <hiqto6.son.ln@localhost>,
  tadmc@flash.net (Tad McClellan) wrote:
> New Book News (noSpam@somedomain.com) wrote:
> : Programming Web Components
> : By Reaz Hoque and Tarun Sharma
>
> : platforms. Java Masters Reaz
> : Hoque and Tarun Sharma bring you
>
>    spam.
>
> : Buy it online:
> :
http://www.amazon.com/exec/obidos/ISBN%3D0079123163/reazhoqueA/002-8026182-4000044
>
>    I've seen calls to boycott Amazon in the past, but I had not seen
>    first hand any abuses by them.
>
>    Now I have.
>
>    Boycott Amazon!
>
>    You can buy books online from:
>
>       http://www.barnesandnoble.com
>
>       http://www.borders.com


I could have provided SPAM from AMAZON, if that is what you needed.
May be I am a bit sensitive, but I don't quite understand why you
add the URLs of two other online bookstore chaines in your response.

IMHO, either you add thousands of other online bookstores' URL from all
of which you can order those books and which don't SPAM or you don't add
any URL.

Do I miss a point here ? Sorry for the off-topic response.

Birgitt Funk


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


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

Date: Mon, 20 Jul 1998 11:19:37 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Wierd behaviour of .. operator
Message-Id: <MPG.101d2a108a4bcc03989729@nntp.hpl.hp.com>

[This followup was posted to comp.lang.perl.misc and a copy was sent to 
the cited author.]

In article <ant201621868Rr9i@waveney.demon.co.uk> on Mon, 20 Jul 1998 
17:49:21 +0100, Richard Proctor <Richard@waveney.demon.co.uk> says...
 ... 
> foreach('A1'..'A13') ...
> 
> And had expected the loop to operate with A1, A2, A3, A4, A5, A6, A7, A8, A9,
> A10, A11, A12 and A13.  BUT was rather surprised to find it generate A1..A9, 
> then B0..B9 ... Z9 then continue with AA0..AA9 ... ZZ0..ZZ9!  Thus 
> generating  7019 values rather than the 13 I had expected (it never did
> generate A10 .. A13). 'A1'..'A9' behaves as expected.
> 
> Now when I realised what had happend, I trivially corrected the problem, 
> however could somebody explain why it did this?  Is it a bug?  Should 
> it generate a warning?  (I did use -w before you ask)

It is a 'magic' feature, not a bug, and is very explicitly documented in 
perlop under 'Autoincrement and Decrement':  "If, however, the variable 
has only been used in string contexts since it was set, and has a value 
that is not null and matches the pattern /^[a-zA-Z]*[0-9]*$/, the 
increment is done as a string, preserving each character within its 
range, with carry: ..."

I presume your trivial fix was to change 'A1' to 'A01'.

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


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

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

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