[10674] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4266 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Nov 20 18:17:18 1998

Date: Fri, 20 Nov 98 15:00:20 -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, 20 Nov 1998     Volume: 8 Number: 4266

Today's topics:
    Re: [PLEASE HELP]: Eliminate spaces at end of string (Jonathan Bobin)
    Re: [PLEASE HELP]: Eliminate spaces at end of string <uri@fastengines.com>
        Attempt to free unreferenced scalar  - ERROR - what doe <neelam@healtheon.com>
        CGI.pm: How to translate newlines and so forth. <jarrod@alcmn.org>
    Re: CGI.pm: How to translate newlines and so forth. (K. Krueger)
    Re: CGI.pm: How to translate newlines and so forth. <jarrod@alcmn.org>
        chmod <oldsen@alpirsbach.netsurf.de>
    Re: chmod (K. Krueger)
    Re: chmod <oldsen@alpirsbach.netsurf.de>
        compare list elements within if statement pjgeer@my-dejanews.com
    Re: compare list elements within if statement (Larry Rosler)
    Re: Environment variables.... <zenin@bawdycaste.org>
        Error in "make test" sysio.t ftidev@fhb.clickcharge.com
    Re: Hashed array printing ? <r28629@email.sps.mot.com>
        help with a new game dragonelf@webtv.net
    Re: How secured my flat database could be using cgi? <jarrod@alcmn.org>
        How to write to an Access database <chrisOlden@t-online.de>
    Re: Net-Whois-0.22 broken? <erikd@zip.com.au>
    Re: NT + Perl + redirection of output (Tye McQueen)
        Problems with Comm.pl on RH5.2 <fournierc@psi.ca>
    Re: puzzler (David Alan Black)
    Re: puzzler <rmlynch@best.com>
    Re: puzzler (felix sheng)
    Re: puzzler (David Alan Black)
    Re: reset one variable? <baliga@synopsys.com>
    Re: scripts similar to hotmail (Erik)
    Re: Stdin <delonad@netdoor.com>
    Re: Stdin (Matthew Bafford)
    Re: Sum by group (Claes Bjorklund)
        SybPerl on Linux <mcurley@newscorp.com>
    Re: Win32::AdminMisc::UserSetMiscAttributes (Was Re: Wi (Tye McQueen)
        Special: Digest Administrivia (Last modified: 12 Mar 98 (Perl-Users-Digest Admin)

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

Date: 20 Nov 1998 22:02:25 GMT
From: jonathan@core.dumped.org (Jonathan Bobin)
Subject: Re: [PLEASE HELP]: Eliminate spaces at end of string
Message-Id: <slrn75bqad.co.jonathan@core.dumped.org>

In article <36540508.D141C89F@online.no>, Hossein Hayati Karun wrote:
>Try this one:
>
>Not tested:
>$s =~ s/(\w)+\s+$/$1/;
>this one should remove all remaining spaces untill end of string/line.

That does not work in all cases.
$string =~ s/ +$//g; should work if you're trying to nuke ending spaces.


-- 

Jonathan Bobin      http://members.xoom.com/moocat     jonathan@core.dumped.org
Got Mole problems? Call Avogadro, 6.022 * 10^23.



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

Date: 20 Nov 1998 17:37:09 -0500
From: Uri Guttman <uri@fastengines.com>
To: jonathan@core.dumped.org (Jonathan Bobin)
Subject: Re: [PLEASE HELP]: Eliminate spaces at end of string
Message-Id: <sar90h6at49.fsf@camel.fastserv.com>

>>>>> "JB" == Jonathan Bobin <jonathan@core.dumped.org> writes:

  JB> In article <36540508.D141C89F@online.no>, Hossein Hayati Karun wrote:
  >> Try this one:
  >> 
  >> Not tested:
  >> $s =~ s/(\w)+\s+$/$1/;
  >> this one should remove all remaining spaces untill end of string/line.

  JB> That does not work in all cases.
  JB> $string =~ s/ +$//g; should work if you're trying to nuke ending spaces.

this is an FAQ. why post anything else but that answer. 

you don't need the /g since you are using +.

hth,

uri

-- 
Uri Guttman                  Fast Engines --  The Leader in Fast CGI Technology
uri@fastengines.com                                  http://www.fastengines.com


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

Date: Fri, 20 Nov 1998 12:18:49 -0800
From: Neelam Saini <neelam@healtheon.com>
Subject: Attempt to free unreferenced scalar  - ERROR - what does it mean ?
Message-Id: <3655CEA9.9FDEC3F3@healtheon.com>

Hi,
I am getting this error while running a perl script. I get a core dump
after this. I am new to perl and can't grasp what the error means.


(W) Perl went to decrement the reference count of a scalar to see if it
    would go to 0, and discovered that it had already gone to 0 earlier,

    and should have been freed, and in fact, probably was freed.  This
    could indicate that SvREFCNT_dec() was called too many times, or
that
    SvREFCNT_inc() was called too few times, or that the SV was
mortalized
    when it shouldn't have been, or that memory has been corrupted.



Thanks for the help.

NS



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

Date: Fri, 20 Nov 1998 15:18:42 -0600
From: Jarrod Stenberg <jarrod@alcmn.org>
Subject: CGI.pm: How to translate newlines and so forth.
Message-Id: <3655DB25.AA13A701@alcmn.org>

I'm finally trying to dig into CGI.pm.
My problem: I need to take any formatting submitting within a form and
send it back to the user as html EXACTLY as it appeared in the form (or
almost).

Also, I'm interested in saving the session but only one parameter:

sub save_parameters {
    local($query) = @_;
    local($filename) = &clean_name($query->param('savefile'));
    if (open(FILE,">$filename")) {
        $query->save(FILE);
        close FILE;
        print "<STRONG>State has been saved to file
$filename</STRONG>\n";
    } else {
        print "<STRONG>Error:</STRONG> couldn't write to file $filename:
$!\n";
    }
}

produces a file that looks like so:
popup1=meenie
popup2=et
text=hello%20there%0D%0Abuddy
savefile=state.sav
action=save

But I only want:

text=hello%20there%0D%0Abuddy

or:
hello%20there%0D%0Abuddy

So just slap me please and send me in the right direction.  I think I'm
bone-heading on the object stuff.

Thanks,
-jarrod




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

Date: 20 Nov 1998 13:34:53 -0800
From: kirbyk@best.com (K. Krueger)
Subject: Re: CGI.pm: How to translate newlines and so forth.
Message-Id: <734n9t$a2s$1@shell2.ba.best.com>

In article <3655DB25.AA13A701@alcmn.org>,
Jarrod Stenberg  <jarrod@alcmn.org> wrote:
>I'm finally trying to dig into CGI.pm.
>My problem: I need to take any formatting submitting within a form and
>send it back to the user as html EXACTLY as it appeared in the form (or
>almost).
>
>Also, I'm interested in saving the session but only one parameter:
>
>sub save_parameters {
>    local($query) = @_;
>    local($filename) = &clean_name($query->param('savefile'));
>    if (open(FILE,">$filename")) {
>        $query->save(FILE);
>        close FILE;
>        print "<STRONG>State has been saved to file
>$filename</STRONG>\n";
>    } else {
>        print "<STRONG>Error:</STRONG> couldn't write to file $filename:
>$!\n";
>    }
>}
>
>produces a file that looks like so:
>popup1=meenie
>popup2=et
>text=hello%20there%0D%0Abuddy
>savefile=state.sav
>action=save
>
>But I only want:
>
>text=hello%20there%0D%0Abuddy
>
>or:
>hello%20there%0D%0Abuddy
>
This is, fortunately, pretty easy - you just need to ask for a specific
parameter.  For instance, $query->param("text") returns the value of
that parameter, hello%20there%0D%0Abuddy.

So, instead of your $query->save(FILE) line, just open the file and 
print $query->param("text");


-- 
Kirby Krueger      O-     kirbyk@best.com 
<*> "Most .sigs this small can't open their own jump gate."


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

Date: Fri, 20 Nov 1998 16:05:45 -0600
From: Jarrod Stenberg <jarrod@alcmn.org>
Subject: Re: CGI.pm: How to translate newlines and so forth.
Message-Id: <3655E626.81651C74@alcmn.org>



"K. Krueger" wrote:

> >
> >But I only want:
> >
> >text=hello%20there%0D%0Abuddy
> >
> >or:
> >hello%20there%0D%0Abuddy
> >
> This is, fortunately, pretty easy - you just need to ask for a specific
> parameter.  For instance, $query->param("text") returns the value of
> that parameter, hello%20there%0D%0Abuddy.
>
> So, instead of your $query->save(FILE) line, just open the file and
> print $query->param("text");
>

Actually tried this.  Actually this will spit out:
hello there buddy

but the form submission looked like so:

hello there
buddy

So param('text') is being interpretted by CGI.pm somehow.

So let me reiterate:

The form is sent like so:
name=joe
subject=testing
text=
_________________
|hello there                |
|buddy                      |
|                                 |
|________________|
(pretending we have a textarea here)
and it is saved to a file like so:

name=joe
subject=testing
text=hello%20there%0D%0Abuddy

Then when I restore values using CGI.pm it prints it with the textarea part
of the form just as typed BUT I would like it to also do this when printing
as html.  So the obvious thing to do is: $text=param('text); $text=~ s/%0A/
<BR>/g; print $text; and so on but this does not work because from
$text=param('text) the special characters are already gone (interpreted?).

So 2 questions will likely be answered with one answer.  How do I read
"text=hello%20there%0D%0Abuddy" with the restore feature of cgi.pm without
interpretting the special characters.  AND how do I write only
"text=hello%20there%0D%0Abuddy" to the file without the other parameters.

Basically I'm trying save files so that they are native (in a manner of
speaking) to cgi.pm so that very little needs to be done for cgi.pm to
understand them.

(Sorry if I'm not being too clear. I'm tired an hungry.)

-jarrod




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

Date: Fri, 20 Nov 1998 21:17:05 +0100
From: "Bjvrn Oldsen" <oldsen@alpirsbach.netsurf.de>
Subject: chmod
Message-Id: <3655CE41.C4009EE7@alpirsbach.netsurf.de>

Hi


How can I apply chmod to read,write and execute on unix with
perl(cgi)-code

Bjoern



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

Date: 20 Nov 1998 13:31:22 -0800
From: kirbyk@best.com (K. Krueger)
Subject: Re: chmod
Message-Id: <734n3a$9j0$1@shell2.ba.best.com>

In article <3655CE41.C4009EE7@alpirsbach.netsurf.de>,
Bjvrn Oldsen <oldsen@alpirsbach.netsurf.de> wrote:
>Hi
>
>
>How can I apply chmod to read,write and execute on unix with
>perl(cgi)-code
>
chmod (0666, $filename);

If you do a 'perldoc perlfunc', and search for chmod, you'll find the
useful documentation on this.  In fact, that's a good general idea for
looking for a simple question like this - as well as the indexes of
the O'Reilly perl books, if you have them.  Always read the documentation
if possible before posting.


-- 
Kirby Krueger      O-     kirbyk@best.com 
<*> "Most .sigs this small can't open their own jump gate."


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

Date: Fri, 20 Nov 1998 22:48:46 +0100
From: "Bjvrn Oldsen" <oldsen@alpirsbach.netsurf.de>
Subject: Re: chmod
Message-Id: <3655E3BD.78F347E@alpirsbach.netsurf.de>

Thanx a lot! I'll try..

K. Krueger wrote:

> In article <3655CE41.C4009EE7@alpirsbach.netsurf.de>,
> Bjvrn Oldsen <oldsen@alpirsbach.netsurf.de> wrote:
> >Hi
> >
> >
> >How can I apply chmod to read,write and execute on unix with
> >perl(cgi)-code
> >
> chmod (0666, $filename);
>
> If you do a 'perldoc perlfunc', and search for chmod, you'll find the
> useful documentation on this.  In fact, that's a good general idea for
> looking for a simple question like this - as well as the indexes of
> the O'Reilly perl books, if you have them.  Always read the documentation
> if possible before posting.
>
> --
> Kirby Krueger      O-     kirbyk@best.com
> <*> "Most .sigs this small can't open their own jump gate."



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

Date: Fri, 20 Nov 1998 22:06:08 GMT
From: pjgeer@my-dejanews.com
Subject: compare list elements within if statement
Message-Id: <734p43$d0n$1@nnrp1.dejanews.com>

I want to compare elements between two lists searching for a match.  But I
want to do it in a single line of code thats < 80 characters long.  I want
this chunk of code to act as the test condition of an if statement, like: if(
chunk_of_code_that_tries_to_find_a_match_between_two_lists ) Thanks, Phil

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


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

Date: Fri, 20 Nov 1998 14:45:08 -0800
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: compare list elements within if statement
Message-Id: <MPG.10bf90cfa0fcaa9c989884@nntp.hpl.hp.com>

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

In article <734p43$d0n$1@nnrp1.dejanews.com> on Fri, 20 Nov 1998 
22:06:08 GMT, pjgeer@my-dejanews.com <pjgeer@my-dejanews.com> says...
> I want to compare elements between two lists searching for a match.  But I
> want to do it in a single line of code thats < 80 characters long.  I want
> this chunk of code to act as the test condition of an if statement, like: if(
> chunk_of_code_that_tries_to_find_a_match_between_two_lists ) Thanks, Phil

I can do it in much fewer than 80 characters, even with plenty of white 
space.  The key is, of course, in perlfaq4: "How can I tell whether an 
array contains a certain element?"

This has all the earmarks of a homework assignment.  I hope your 
instructor will be happy.

#!/usr/local/bin/perl -w
use strict;

my @a = (0 .. 9 );
my @b = ('a' .. 'z', 0);

if (do { my %h; @h{@a} = (); grep exists $h{$_}, @b }) {
    print "matched\n";
}

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


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

Date: 20 Nov 1998 22:38:51 GMT
From: Zenin <zenin@bawdycaste.org>
Subject: Re: Environment variables....
Message-Id: <911601264.627431@thrush.omix.com>

[posted & mailed]

Casema <ours@casema.net> wrote:
: I am trying to figure out how to write a counter-script.
: I want one that determines the browser and platform. As well as screen res.
: I then can optimize my pages!

	%ENV contains your environment.  You can tell the browser and
	platform, with a bit of work.  Screen res isn't going to happen
	at all however.

	The CGI newsgroups would be better suited to your needs as well.

-- 
-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: Fri, 20 Nov 1998 22:35:17 GMT
From: ftidev@fhb.clickcharge.com
Subject: Error in "make test" sysio.t
Message-Id: <734qr4$ehb$1@nnrp1.dejanews.com>

Environment:
Digital Unix 4.0D (Alpha)
perl5.005_53

The post-build test sysio.t fails
not ok 29
not ok 31
not ok 32
not ok 33

This part of the test is testing syswrite.
Has anyone seen this before?  Does anyone have suggestions?
Can it be ignored?

The problem is not seen in 5.004-4.

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


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

Date: Fri, 20 Nov 1998 14:17:28 -0600
From: Tk Soh <r28629@email.sps.mot.com>
Subject: Re: Hashed array printing ?
Message-Id: <3655CE58.2228E735@email.sps.mot.com>

Douglas K. O'Leary wrote:
> 
> Uri Guttman <uri@sysarch.com> wrote:
> : you don't need the \ to continue lines in per;l.
> 
> And, so it turns out that it was a dumb newbie question after all.
> Thank you for help; that was the answer.

when it has to come to ref, it could be dumb ;), but rarely is a newbie
question. 

-TK


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

Date: Fri, 20 Nov 1998 17:02:37 -0500 (EST)
From: dragonelf@webtv.net
Subject: help with a new game
Message-Id: <6045-3655E6FD-72@newsd-113.bryant.webtv.net>


--WebTV-Mail-1045780578-6229
Content-Type: Text/Plain; Charset=US-ASCII
Content-Transfer-Encoding: 7Bit

what would be better to use to build a text multiplayer game? perl, c++,
basic? any responses please


--WebTV-Mail-1045780578-6229
Content-Description: signature
Content-Disposition: Inline
Content-Type: Text/HTML; Charset=US-ASCII
Content-Transfer-Encoding: 7Bit

<html><center><img
src="http://www.geocities.com/~rworne/pokemon/pikachu-l.gif" width="100"
height="140">    <A
HREF=http://156.46.156.32/slaw-bin/rock/torock.pl?pikachu> <IMG
SRC=http://156.46.156.32/r2/images/rocknow.gif BORDER=0 WIDTH=123
HEIGHT=30 ALIGN=ABSMIDDLE></A>
    <img
src="http://www.comicnexus.com/comicnexus/images/videos/1998_11/pokemon.jpg">
</center>
<hr><right>
<b>-Pikachu</b></html>
</right>


--WebTV-Mail-1045780578-6229--


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

Date: Fri, 20 Nov 1998 15:37:45 -0600
From: Jarrod Stenberg <jarrod@alcmn.org>
Subject: Re: How secured my flat database could be using cgi?
Message-Id: <3655DF9A.D561B445@alcmn.org>

>
> 1.
> From my script I give read access to my database and I put
> a chmod 744 database.dat permission.  So, far it is ok.  If
> my database is readable, can someone else read the file by
> bypassing the cgi script and have access to private data?
> How can I prevent that?
>

I say use CGI.pm.  Takes car of security for you.

>
> 2.
> From my script I give write access to my database and I put
> a chmod 742 database.dat permission.  So, far it is ok.  If
> my database is writable, can someone else write in the file by
> bypassing the cgi script and corrupt my private data?
> How can I prevent that?

If you mean that someone can go into http://www.you.com/data/ (which is
normally accessed via the cgi) and index all that's in there, a real
simple way to keep people out is to put an index.html file with a
redirect or an index.cgi script that sends them the right direction.

-jarrod



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

Date: Fri, 20 Nov 1998 16:36:47 +0100
From: "Chris" <chrisOlden@t-online.de>
Subject: How to write to an Access database
Message-Id: <734p5j$ph6$1@usenet43.supernews.com>

I have a text File that looks like this:

Key 1012 1045 1986
Key2 3245 5678 2345 5675
 .....

What I want is to write to an Access database which contains of two fields,
a Ref-Number and Keywords. So the Keyword in front of the line in my text
file should be added to the keyword field of every ref number that follows.

So I wonder
-How do I write to a specific column in a4n access database
-Can I append data
-How do I work with my text file

Any help would be appreciated. Please answer via E-mail
ChrisOlden@T-Online.de

Thanks in advance,
                                   Chris




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

Date: Sat, 21 Nov 1998 09:22:54 +1100
From: Erik de Castro Lopo <erikd@zip.com.au>
Subject: Re: Net-Whois-0.22 broken?
Message-Id: <3655EBBE.4FD50B50@zip.com.au>

Ben Duncan wrote:
> 
> > I was just wondering if anyone has had any
> > success in using the Perl Module Net-Whois-0.22.
> 
> Hmm. I guess not :)

I posted an example of looking up a whois server using Net::Telnet 
on comp.lang.perl.misc a week or two back. You should be able to 
find it on www.dejanews.com.

The problem with Net-Whois-0.22 seems to be that the whois is
server at whois.internic.net (the main global one) has changed
the way it answers requests, breaking many existing 
implementations. I also posted (another reply unfortunately) a 
link to a web page explaining what had changed and how to fix it.

Cheers,
Erik
-- 
+-------------------------------------------------+
     Erik de Castro Lopo     erikd@zip.com.au
+-------------------------------------------------+
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: 20 Nov 1998 13:58:44 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: NT + Perl + redirection of output
Message-Id: <734hlk$c57@fohnix.metronet.com>

) On Tue, 17 Nov 1998 20:42:36 GMT, mcnay@my-dejanews.com wrote:
) >I am having problems with redirecting the output of a perl
) >script into a file.
) >example:   update.plx -i xt -p 100 >>.update.log

tnguru@termnetinc.com (Ben Coleman) writes:
) This is a known problem with NT:  redirection doesn't work with anything
) but ordinary executables and command/batch files.  Blame Microsoft.

Not a very helpful response.  See the Win32 Perl FAQ (via
http://www.dejanews.com/ or http://www.perl.com/ among other
places) for more information.  My suggestions is to use pl2bat
on update.plx to give you update.bat and change your example
to:

	update -i xt -p 100 >>.update.log

(one version of a Win32 Perl FAQ said pl2bat didn't fix the
redirect problem under NT, but that is wrong)

The only disadvantage I can think of to this approach is that
using update.bat from within a *.bat file requires that you use
"call update ...".
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

Date: Fri, 20 Nov 1998 16:54:50 -0500
From: "Christopher J. Fournier" <fournierc@psi.ca>
Subject: Problems with Comm.pl on RH5.2
Message-Id: <3655E529.FC036ED@psi.ca>

Has anyone else encountered problems with the Comm.pl module under
Redhat 5.2 (2.0.36)? Perl5.00404 is the default install, but now my
socket calls won't work... !?



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

Date: 20 Nov 1998 15:18:53 -0500
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: puzzler
Message-Id: <734ird$gs9$1@pilot.njin.net>

Hello -

In comp.lang.perl.misc you write:

>Is there a good trick for transposing a two dimensional array?	That is,
>combine a two dimensional array into a one dimensional array columnwise: 1st
>element/1st row followed by 1st element/2nd row, etc.  There must be some way
>to streamline what I wrote.


I do know that temporary variables really are OK - and that this code is almost
certainly less efficient than it would be if it used some - but I do love
the "look and feel" of purely functional solutions :-)  I'm not entirely
thrilled with the grepping, but anyway....  (Oh, and I'm following your
lead in allowing a destructive solution.)

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

my @lol = (
        [ "fred", "barney" ],
        [ "george", "judy", "elroy" ],
        [ "homer", "lisa",  "bart" ],
        ) ;

my @new = grep { $_ } map { map { shift @$_ } @lol }
           (0..(sort map { scalar @$_ } @lol)[-1]-1);

print "@new\n";  # fred george homer barney judy lisa elroy bart

__END__


David Black
dblack@pilot.njin.net



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

Date: Fri, 20 Nov 1998 14:08:40 -0800
From: Robert Lynch <rmlynch@best.com>
Subject: Re: puzzler
Message-Id: <3655E868.EA0B115@best.com>

I came up with this:
----
my @LOL = (
        [ "fred", "barney" ],
        [ "george", "judy", "elroy" ],
        [ "homer", "lisa", "bart" ],
        ) ;

for(0..$#LOL) {
    $k = $_;
    @final = (@final, map { $_->[$k] } @LOL)
}

print "@final\n"
----
but I'm not happy that there's an undefined value in there which is
revealed with "-w", and here by a space:

[user@ravel perl]$ perl trans1.pl
fred george homer barney judy lisa  elroy bart

I tried sticking "defined" in various places, but no joy.

Bob L.
-- 
Robert Lynch-Berkeley CA USA-rmlynch@best.com
http://www.best.com/~rmlynch/
--
jschueler@detroit.usweb.com wrote:
> 
> Is there a good trick for transposing a two dimensional array?  That is,
> combine a two dimensional array into a one dimensional array columnwise: 1st
> element/1st row followed by 1st element/2nd row, etc.  There must be some way
> to streamline what I wrote.
> 
> The following code prints out:
> 
> fred
> george
> homer
> barney
> judy
> lisa
> elroy
> bart
> 
> ------------------ begin code --------------------
> #! /usr/bin/perl5
> 
> my @LOL = (
>         [ "fred", "barney" ],
>         [ "george", "judy", "elroy" ],
>         [ "homer", "lisa", "bart" ],
>         ) ;
> 
> my $IDX ;
> my @RETVAL = () ;
> 
> while ( @LOL ) {
>         shift @LOL while ( @LOL && ! @{ $LOL[0] } ) ;
>         for ( $IDX = 0 ; @LOL && @{ $LOL[$IDX] } ; $IDX++ ) {
>                 push( @RETVAL, shift @{ $LOL[$IDX] } ) ;
>                 }
>         }
> 
> print join "\n", @RETVAL ;
> print "\n" ;
> 
> -----------== Posted via Deja News, The Discussion Network ==----------
> http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


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

Date: 20 Nov 1998 22:15:32 GMT
From: shengf@wolfgang.ms.com (felix sheng)
Subject: Re: puzzler
Message-Id: <734pm4$rik@sanews1.morgan.com>

<jschueler@detroit.usweb.com> wrote:
> Is there a good trick for transposing a two dimensional array?    That is,
> combine a two dimensional array into a one dimensional array columnwise: 1st
> element/1st row followed by 1st element/2nd row, etc.  There must be some way
> to streamline what I wrote.

You might try something like this:

my @LOL = (
             [ "fred", "barney" ],
             [ "george", "judy", "elroy" ],
             [ "homer", "lisa", "bart" ],
          ); 

my( @curarr, @arr );
for(my $i=0;1;++$i) {
   my @curarr = grep length, map { $_->[$i] } @LOL;
   last unless @curarr;
   push @arr, @curarr;
} 

print "@arr\n"; #fred george homer barney judy lisa elroy bart

It started out as a recursive function, but as these things work out, 
it's much better iterative.

felix

-- 
             felix k sheng * <shengf@ms.com> * 212 762 4483
--


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

Date: 20 Nov 1998 17:54:39 -0500
From: dblack@pilot.njin.net (David Alan Black)
Subject: Re: puzzler
Message-Id: <734rvf$ibl$1@pilot.njin.net>

Hello -

Robert Lynch <rmlynch@best.com> writes:

>I came up with this:
>----
>my @LOL = (
>        [ "fred", "barney" ],
>        [ "george", "judy", "elroy" ],
>        [ "homer", "lisa", "bart" ],
>        ) ;

>for(0..$#LOL) {
>    $k = $_;
>    @final = (@final, map { $_->[$k] } @LOL)
>}

>print "@final\n"
>----
>but I'm not happy that there's an undefined value in there which is
>revealed with "-w", and here by a space:

>[user@ravel perl]$ perl trans1.pl
>fred george homer barney judy lisa  elroy bart

>I tried sticking "defined" in various places, but no joy.


That's what got me using "grep { $_ }".  But there's another problem
with your version.  You're using the range 0..$#LOL to iterate
through the arrays of names - which will fail if any of those
arrays has more elements than @LOL itself has.  

Thus the example above only works by coincidence.  If you add,
say, "marge" to the last list, you still won't see "marge"
printed, because $k never goes any higher than $#LOL (which
is 2, whereas "marge" would be at index 3).

(I suppose this is a good time to confess that my first solution,
which I emailed but didn't post, had exactly this flaw in it :-)


David Black
dblack@pilot.njin.net




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

Date: Fri, 20 Nov 1998 14:04:40 -0800
From: Yogish Baliga <baliga@synopsys.com>
To: dropzone@mail.utexas.edu
Subject: Re: reset one variable?
Message-Id: <3655E778.E100EBFE@synopsys.com>

you can use undef

-- Baliga

forrest reynolds wrote:

> Hello,
>              I'm looking in the Camel book at "reset".... it doesn't
> mention resetting
> just one variable. Is this possible without using:
>
>               $var = "" ;
>
> Thanks ,Forrest



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

Date: 20 Nov 1998 17:08:13 GMT
From: eln@cyberhighway.net (Erik)
Subject: Re: scripts similar to hotmail
Message-Id: <7347lt$q2j$1@news.cyberhighway.net>

In article <364DCB23.9E1F8D3E@usa.net>,
	CTT <00000ctt@usa.net> writes:
> I'd like to creat a web based email system like hotmail in my server, i
> know how to do the pop3 mail stuff in perl, but i dont know how to do
> the add user stuff in unix.....what command should i use in order to
> creat a new user (with email account)?

This question a.) has nothing to do with perl, and b.) is entirely
platform-specific, depending not only on what flavor of unix you're
running, but what MTA you're running along with it.  Check the
documentation for your OS and your MTA.  HTH!

-- 
Erik Nielsen, Cyberhighway Internet Services NOC
Is there a tape drive that isn't a DLT that doesn't suck dead weasels through
a lint-clogged dryer hose? 
             -- Peter da Silva in a.s.r.


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

Date: Fri, 20 Nov 1998 14:25:40 -0600
From: Aaron Delong <delonad@netdoor.com>
Subject: Re: Stdin
Message-Id: <Pine.GSO.4.05.9811201424540.22641-100000@lance.netdoor.com>

while (<STDIN>)
{
     print $_;
}

The code above should echo all data submitted via stdin.

On Thu, 19 Nov 1998, Matthew Foley wrote:

> How do i read info from stdin in and parse it as a varible.  Thanks
> 
> 
> 
> 



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

Date: Fri, 20 Nov 1998 16:27:32 -0500
From: dragons@scescape.net (Matthew Bafford)
Subject: Re: Stdin
Message-Id: <MPG.10bfa8d3a632b5c989725@news.scescape.net>

[Followups set]

In article <TEj52.626$Oa2.3526@news12.ispnews.com>, Matthew Foley 
<mfoley@richmond.net> pounded in the following:
=> How do i read info from stdin in and parse it as a varible.

Use the filehandle STDIN.

---

Why was this sent to comp.lang.perl.modules?

=> Thanks

Hope This Helped!

--Matthew

-- 
# comp.lang.perl is dead.  Please use comp.lang.perl.misc or
# comp.lang.perl.moderated.  Thanks!


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

Date: Fri, 20 Nov 1998 23:41:40 +0100
From: claes_no_spam@canit.se (Claes Bjorklund)
Subject: Re: Sum by group
Message-Id: <claes_no_spam-2011982341410001@p34.one.canit.se>

In article <734gi1$5io$1@nnrp1.dejanews.com>, ptimmins@netserv.unmc.edu
(Patrick Timmins) wrote:

>In article <73442a$q21$1@nnrp1.dejanews.com>,
>  c_b9209@my-dejanews.com wrote:
>
>> Hi
>>
>> I want to sum by group in a data file were the first column has groups values
>> and other has regular values. The data file is really huge
>> here is a script for small file but it doesn't works for a big one,please can
>> anyone help me this problem make me crazy
>
>You posted this question once before under a different subject header
>... why?
I am sorry, I posted via dejanews for the first time and thought I did
something wrong and then the message was gone so I rewrite it and posted
again.
Thanks for your response I will look at the script now, maybe I have more
qustions later

\Claes
>
>Again:
>
>while (<DATA>) {
>   @temp = split/\s+/;
>   for ($i=1; $i<@temp; $i++) {
>      push @{$group{$temp[0]}{$i}}, $temp[$i];
>   }
>}
>
>foreach $grp (sort keys %group) {
>   foreach $clmn (sort keys %{ $group{$grp} } ) {
>      $sum = 0;    # have to reset this each time through the loop
>      $cnt = @{ $group{$grp}{$clmn} };
>      for ($i=0; $i<@{ $group{$grp}{$clmn} }; $i++) {
>         $sum += $group{$grp}{$clmn}[$i];
>      }
>      print "Group $grp column $clmn: sum = $sum, n = $cnt\n";
>   }
>}
>__DATA__
>setA 1 2 3 4
>setB 5 6 7 8
>setA 9 10 11 12
>setB 13 14 15 16
>
>will print out:
>
>Group setA column 1: sum = 10, n = 2
>Group setA column 2: sum = 12, n = 2
>Group setA column 3: sum = 14, n = 2
>Group setA column 4: sum = 16, n = 2
>Group setB column 1: sum = 18, n = 2
>Group setB column 2: sum = 20, n = 2
>Group setB column 3: sum = 22, n = 2
>Group setB column 4: sum = 24, n = 2
>
>Patrick Timmins
>$monger{Omaha}[0]
>
>-----------== Posted via Deja News, The Discussion Network ==----------
>http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own


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

Date: Fri, 20 Nov 1998 16:39:17 -0500
From: "Morgan Curley" <mcurley@newscorp.com>
Subject: SybPerl on Linux
Message-Id: <734ni7$5bq$1@fisher.nis.newscorp.com>

Has anyone out there successfully installed Sybperl on RH 5.o with either
the Sybase Open Client Libs or Sybase's ASE 11.0.3.3??
If you have, please give me some hints at least, this process seems to be
way beyond me.

Thanks
Morgan





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

Date: 20 Nov 1998 14:14:56 -0600
From: tye@fohnix.metronet.com (Tye McQueen)
Subject: Re: Win32::AdminMisc::UserSetMiscAttributes (Was Re: Win32 UserCreate )
Message-Id: <734ik0$gpq@fohnix.metronet.com>

Jimmer <jimmr@evolution.org> writes:
) Here is your original code:
[...]
) Win32::AdminMisc::UserSetMiscAttributes('', 'OdinTest789',
)                 USER_HOME_DIR_DRIVE, "i:",)||print "No Set!!!\n";
) Win32::AdminMisc::UserGetMiscAttributes('', 'OdinTest789', \%hash) ||
[....]
) You need to change the "i:" from double quotes to single quotes like
) this: 'i:'. Once you do this you will set the USER_HOME_DIR_DRIVE=i:.

Sorry, that change can't possibly make a difference.  C<"i:"> and
C<'i:'> are identical in Perl.

)   print "$i = ". $hash{$i} ."\n";

    print "$i= $hash{$i}\n";

also works for that, just FYI.

Sorry, I don't have the solution for the original problem.  I'd
write C<USER_HOME_DIR_DRIVE> as C<USER_HOME_DIR_DRIVE()> so you'll
get an error if you mistype the name, though.
-- 
Tye McQueen    Nothing is obvious unless you are overlooking something
         http://www.metronet.com/~tye/ (scripts, links, nothing fancy)


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

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

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