[24779] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 6932 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Aug 30 09:06:52 2004

Date: Mon, 30 Aug 2004 06:05:09 -0700 (PDT)
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, 30 Aug 2004     Volume: 10 Number: 6932

Today's topics:
    Re: angle operator behavior with filehandles in @_ (Anno Siegel)
    Re: Apache Cookie Issue (Sara)
        Emacs modules for Perl programming (Jari Aalto+mail.perl)
    Re: Execute Windows program from Perl script (??) <tintin@invalid.invalid>
    Re: how many days ago is 2003-07-20 ? <noreply@gunnar.cc>
    Re: how many days ago is 2003-07-20 ? (Anno Siegel)
    Re: how many days ago is 2003-07-20 ? <noreply@gunnar.cc>
    Re: Larry Wall & Cults <Brian.Inglis@SystematicSW.Invalid>
    Re: Larry Wall & Cults <bik.mido@tiscalinet.it>
    Re: Larry Wall & Cults (norman werner)
    Re: Parsing a text file into an array (Sara)
        passing arguments to subroutines <romanr@cablespeed.com>
    Re: passing arguments to subroutines <noreply@gunnar.cc>
    Re: passing arguments to subroutines <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: passing arguments to subroutines <josef.moellers@fujitsu-siemens.com>
    Re: perl - data structure build to transpose data (shree)
    Re: perl - data structure build to transpose data <someone@example.com>
    Re: perl and memory (Anno Siegel)
        Reading Unicode File and Saving Contents to Access <qjason@starhub.net.sg>
    Re: Reference to functions <bernard.el-haginDODGE_THIS@lido-tech.net>
    Re: Removing entries in array based on another array <leifwessman@hotmail.com>
    Re: Removing entries in array based on another array <leifwessman@hotmail.com>
    Re: Removing entries in array based on another array (Anno Siegel)
    Re: Removing entries in array based on another array <leifwessman@hotmail.com>
    Re: Removing entries in array based on another array <noreply@gunnar.cc>
        Using SSL certificates with LWP <trondmm-usenet@crusaders.no>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: 30 Aug 2004 10:08:52 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: angle operator behavior with filehandles in @_
Message-Id: <cguubk$sp4$1@mamenchi.zrz.TU-Berlin.DE>

Joe Smith  <Joe.Smith@inwap.com> wrote in comp.lang.perl.misc:
> John Bullock wrote:

[...]

> This section from 'perldoc perlop':
> 
>      If what the angle brackets contain is a simple scalar variable (e.g.,
>      <$foo>), then that variable contains the name of the filehandle to
>      input from, or its typeglob, or a reference to the same.  For example:
> 
>          $fh = \*STDIN;
>          $line = <$fh>;
> 
>      If what's within the angle brackets is neither a filehandle nor a sim-
>      ple scalar variable containing a filehandle name, typeglob, or typeglob
                           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
>      reference, it is interpreted as a filename pattern to be globbed, and
       ^^^^^^^^^
>      either a list of filenames or the next filename in the list is
>      returned, depending on context.  This distinction is determined on syn-
>      tactic grounds alone.  That means "<$x>" is always a readline() from an
>      indirect handle, but "<$hash{key}>" is always a glob().  That's because
>      $x is a simple scalar variable, but $hash{key} is not--it's a hash ele-
>      ment.

The hilighted clause makes the sentence ambiguous.  I would read it as
saying that for a thing to be taken as a filehandle it must (a) be
a simple scalar variable and (b) contain a filehandle name, typeglob,
or typeglob reference.  Only the next sentence ("on syntactic grounds
alone") makes clear that it means the variable must be a simple variable,
which then, (to make sense) must contain one of those things.

I'd suggest changing the second paragraph to:

       If what's within the angle brackets is neither a filehandle 
       nor a simple scalar variable, its content (any string value)
       will be interpreted as a filename pattern to be globbed, and
       either a list of filenames or the next filename in the list is 
       returned, depending on context.  This distinction is determined
       on syntactic grounds alone. ...

Anno


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

Date: 30 Aug 2004 05:29:36 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: Apache Cookie Issue
Message-Id: <776e0325.0408300429.5a175183@posting.google.com>

"Marcellus Wallace" <marcelluswallace@hotpop.com> wrote in message news:<fasYc.204214$8_6.16366@attbi_s04>...
> i've been trying to fix this all day, and could use some help
> 
> my setup:
> 
> i have an apache server (1.3.29 on linux) on my home network.  I use this
> server for development (perl).
> 
> i have a site that uses Apache::AuthCookie for authentication
> 
> i access this site through 192.168.0.56/nameofsite.com
> 
> submitting the login form (username/password) sets the cookie and I'm in,
> always has worked until today.
> 
> all of a sudden I can't set cookies when accessing this server.  It still
> worked using firefox so I figured it may be my IE, but I've tried it from IE
> on 3 different machines on the network that haven't been touch in a while
> and same result.  also have tried the live site (different server) with IE
> and it works fine (same exact code, even brought that code down to my dev
> machine to check, no go)
> 
> I tried setting IE to prompt for cookies and there is no prompt, it's as if
> it's automatically blocking IE cookies.  I know if it's checking against the
> database because if I put in the wrong password it tell me so.  So again,
> it's for some reason auto rejecting IE cookies.
> 
> 
> Any help would be appreciated and please reply to the group.
> 
> Thanks

I think this is helpful: you need to ask this question in an apache
newsgroup. It apears to have a void relationship to The Perl
Programming Language.

G


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

Date: 30 Aug 2004 04:46:33 GMT
From: <jari.aalto <AT> poboxes.com> (Jari Aalto+mail.perl)
Subject: Emacs modules for Perl programming
Message-Id: <perl-faq/emacs-lisp-modules_1093841166@rtfm.mit.edu>

Archive-name: perl-faq/emacs-lisp-modules
Posting-Frequency: 2 times a month
URL: http://tiny-tools.sourceforge.net/
Maintainer: Jari Aalto A T poboxes com

Announcement: "What Emacs lisp modules can help with programming Perl"

    Preface

        Emacs is your friend if you have to do anything comcerning software
        development: It offers plug-in modules, written in Emacs lisp
        (elisp) language, that makes all your programmings wishes come
        true. Please introduce yourself to Emacs and your programming era
        will get a new light.

    Where to find Emacs/XEmacs

        o   Unix:
            http://www.gnu.org/software/emacs/emacs.html
            http://www.xemacs.org/

        o   Unix Windows port (for Unix die-hards):
            install http://www.cygwin.com/  which includes native Emacs 21.x.
            and XEmacs port

        o   Pure Native Windows port
            http://www.gnu.org/software/emacs/windows/ntemacs.html
            ftp://ftp.xemacs.org/pub/xemacs/windows/setup.exe

        o   More Emacs resources at
            http://tiny-tools.sourceforge.net/  => Emacs resource page

Emacs Perl Modules

    Cperl -- Perl programming mode

        http://www.cpan.org/modules/by-authors/id/ILYAZ/cperl-mode/
        http://math.berkeley.edu/~ilya/software/emacs/
        by Ilya Zakharevich

        CPerl is major mode for editing perl files. Forget the default
        `perl-mode' that comes with Emacs, this is much better. Comes
        standard in newest Emacs.

    TinyPerl -- Perl related utilities

        http://tiny-tools.sourceforge.net/

        If you ever wonder how to deal with Perl POD pages or how to find
        documentation from all perl manpages, this package is for you.
        Couple of keystrokes and all the documentaion is in your hands.

        o   Instant function help: See documentation of `shift', `pop'...
        o   Show Perl manual pages in *pod* buffer
        o   Grep through all Perl manpages (.pod)
        o   Follow POD references e.g. [perlre] to next pod with RETURN
        o   Coloured pod pages with `font-lock'
        o   Separate `tiperl-pod-view-mode' for jumping topics and pages
            forward and backward in *pod* buffer.

        o   Update `$VERSION' variable with YYYY.MMDD on save.
        o   Load source code into Emacs, like Devel::DProf.pm
        o   Prepare script (version numbering) and Upload it to PAUSE
        o   Generate autoload STUBS (Devel::SelfStubber) for you
            Perl Module (.pm)

    TinyIgrep -- Perl Code browsing and easy grepping

        [TinyIgrep is included in Tiny Tools Kit]

        To grep from all installed Perl modules, define database to
        TinyIgrep. There is example file emacs-rc-tinyigrep.el that shows
        how to set up dattabases for Perl5, Perl4 whatever you have
        installed

        TinyIgrep calls Igrep.el to to do the search, You can adjust
        recursive grep options, set search case sensitivity, add user grep
        options etc.

        You can find latest `igrep.el' module at
        <http://groups.google.com/groups?group=gnu.emacs.sources> The
        maintainer is Jefin Rodgers <kevinr <AT> ihs.com>.

    TinyCompile -- To Browse grep results in Emacs *compile* buffer

        TinyCompile is a minor mode for *compile* buffer from where
        you can collapse unwanted lines or shorten file URLs:

            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file1:NNN: MATCHED TEXT
            /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/file2:NNN: MATCHED TEXT

            -->

            cd /asd/asd/asd/asd/ads/as/da/sd/as/as/asd/
            file1:NNN: MATCHED TEXT
            file1:NNN: MATCHED TEXT

End



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

Date: Mon, 30 Aug 2004 20:20:17 +1200
From: "Tintin" <tintin@invalid.invalid>
Subject: Re: Execute Windows program from Perl script (??)
Message-Id: <2pg69aFk4otcU1@uni-berlin.de>


"Tony McGuire" <tony@paradoxcommunity.com> wrote in message
news:f896a829.0408290633.f6b71a0@posting.google.com...
> > It can be done, but ask yourself the question, "How would I do this in
C,
> > VB, Fortran etc"?  The answer will be the same.
>
> I don't know any of those languages, so I have no idea what the 'same'
> answer might be.

The point of my question is that the answer is language dependent, ie:  they
all would require an equivalent of a system call and the appropriate
permissions set on the requires dirs/files.  The point of the retortical
question (and it is asked quite often) is to make the OP think about
partitioning question.  Too often, people don't understand how the various
technologies work together in the browser/web server/CGI/Perl world.  The
first skill to learn in problem solving is to isolate where the problem
exists.  This can take some time and experience to learn, but it is
certainly an essential skill to learn early on, otherwise you'll end up
chasing your tail.




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

Date: Mon, 30 Aug 2004 03:16:46 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <2pfdknFka41fU1@uni-berlin.de>

Anno Siegel wrote:
> Gunnar Hjalmarsson wrote:
>> Could you possibly give an example when the function would return
>> anything else but the number of complete calendar days since the
>> date that is passed to it?
> 
> I don't remember saying it doesn't.  It would be your job to prove
> that it does, and (a lot harder) to describe the conditions under
> which it does.

My "job"? You asked if I have "a simple, water-tight solution" using
only Time::Local, and I posted this code, which I claim is just that:

     sub daysago {
         shift =~ /^(\d{4})-(\d{2})-(\d{2})$/
           or die "Invalid date format";
         require Time::Local;
         import Time::Local 'timelocal';
         my $diff = timelocal(0,0,0,(localtime $^T)[3..5])
           - timelocal(0,0,0,$3,$2-1,$1-1900);
         $diff >= 0 or die "Future date not allowed";
         sprintf '%.0f', $diff / 86400
     }

     print daysago('2003-07-20'), "\n";

It addresses the trivial task the OP asked for help with: Calculating
the number of days since a certain date.

> My point is that the seemingly clear notion of the number of days
> between two calendar dates must be re-defined in view of the fact
> that two midnights aren't necessarily a multiple of 24 hours apart.

Re-defined? Out from which definition? And why?

The function computes the number of seconds between 00:00:00 at the
comparison date and 00:00:00 at today's date. Switching to or from DST
may result in that number being 3600 seconds less or more than a
multiple of 86400, but such a switch can never affect the full number
of calendar days after rounding by sprintf().

> You assume that rounding is the answer, but other answers could be
> given, which might differ by one under various circumstances.

Which answers would that be? Note that we are talking about comparing
dates. Time of the day is not an input, and should obviously not
affect the result.

> At this point I might decide to use a module that (presumably) has
> come up with a solution that is both consistent in itself and with
> intuitive notions, and which is reasonably general with respect to
> local DST variations.

Nothing wrong with doing so, of course. Personally I think twice
before using a non-standard module, since I usually work with programs
that are intended for distribution, and non-standard modules
complicates the distribution.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: 30 Aug 2004 08:25:51 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <cguoaf$omf$1@mamenchi.zrz.TU-Berlin.DE>

Gunnar Hjalmarsson  <noreply@gunnar.cc> wrote in comp.lang.perl.misc:
> Anno Siegel wrote:
> > Gunnar Hjalmarsson wrote:
> >> Could you possibly give an example when the function would return
> >> anything else but the number of complete calendar days since the
> >> date that is passed to it?
> > 
> > I don't remember saying it doesn't.  It would be your job to prove
> > that it does, and (a lot harder) to describe the conditions under
> > which it does.
> 
> My "job"? You asked if I have "a simple, water-tight solution" using
> only Time::Local, and I posted this code, which I claim is just that:

Quite.  It's your algorithm and your claim.

>      sub daysago {
>          shift =~ /^(\d{4})-(\d{2})-(\d{2})$/
>            or die "Invalid date format";
>          require Time::Local;
>          import Time::Local 'timelocal';
>          my $diff = timelocal(0,0,0,(localtime $^T)[3..5])
>            - timelocal(0,0,0,$3,$2-1,$1-1900);
>          $diff >= 0 or die "Future date not allowed";
>          sprintf '%.0f', $diff / 86400
>      }
> 
>      print daysago('2003-07-20'), "\n";
>
> It addresses the trivial task the OP asked for help with: Calculating
> the number of days since a certain date.
> 
> > My point is that the seemingly clear notion of the number of days
> > between two calendar dates must be re-defined in view of the fact
> > that two midnights aren't necessarily a multiple of 24 hours apart.
> 
> Re-defined? Out from which definition? And why?

To calculate the number of cars in a train from its length, you divide
the length by the length of each car.  That's fine as long as all
cars have the same length.  Now DST comes along and introduces non-
standard long and short cars.  For an arbitrary mixture of cars, the
method breaks down now.  What saves it (with the introduction of
rounding) is the fact that DST introduces its non-standard cars in
particular ways.  It would be necessary to describe exactly what
DST may do and what not (and to make sure that all local implementations
of DST comply) to establish the validity of the method.  That is not
trivial.

Anno


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

Date: Mon, 30 Aug 2004 12:09:01 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: how many days ago is 2003-07-20 ?
Message-Id: <2pgd0gFk1393U1@uni-berlin.de>

Anno Siegel wrote:
> It would be necessary to describe exactly what DST may do and what
> not (and to make sure that all local implementations of DST comply)
> to establish the validity of the method.  That is not trivial.

Can you point me to the corresponding descriptions for Date::Calc and
Date::Manip?

I can't understand why you are trying to turn this trivial task into 
rocket science. You are reasoning as if it was a general purpose 
date/time module or a calendar app.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 30 Aug 2004 05:24:18 GMT
From: Brian Inglis <Brian.Inglis@SystematicSW.Invalid>
Subject: Re: Larry Wall & Cults
Message-Id: <hde5j0hsk6uk96aau8rqi9k99p3v4058i5@4ax.com>

On Sun, 29 Aug 2004 17:02:23 -0700 in alt.folklore.computers, Mac
<foo@bar.net> wrote:

>On Sun, 29 Aug 2004 06:58:30 +0000, Brian Inglis wrote:
>
>> On Sat, 28 Aug 2004 20:59:08 -0700 in alt.folklore.computers, Mac
>> <foo@bar.net> wrote:
>> 
>>>On Wed, 25 Aug 2004 14:56:06 -0700, Xah Lee wrote:
>>>
>>>> Larry Wall and Cults
>>>> (Lazyness, Impatience and Hubris)
>>>> 200012
>> 
>>>> Surely you have heard of Adolf Hitler
>>>> and his atrocities of genocide? I must alert you, that a single person
>>>> couldn't commit such a crime.
>>>
>>>Wow, Godwin's law invoked on the first post of the thread.
>> 
>> Not quite, no comparison was made; see: 
>> http://groups.google.com/groups?as_umsgid=1991Oct22.140831.23313%40eff.org
>
>
>Hmm. No explicit comparison was made, but since the post is a cautionary
>tale (well, the post is a rambling mess, but I think it is trying to be a
>cautionary tale) I think the comparison is understood.
>
>But if the comparison must be explicit, as you seem to be saying, then I
>have to concede the point.

Google for the Godwin's Law FAQ on how to troll on Usenet, mention
Nazis, and not be caught by Godwins' Law. 

-- 
Thanks. Take care, Brian Inglis 	Calgary, Alberta, Canada

Brian.Inglis@CSi.com 	(Brian[dot]Inglis{at}SystematicSW[dot]ab[dot]ca)
    fake address		use address above to reply


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

Date: Mon, 30 Aug 2004 08:19:18 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: Larry Wall & Cults
Message-Id: <ie04j09aicmhtquf4n2sk9msq2t2b6teap@4ax.com>

On Thu, 26 Aug 2004 09:49:48 +0200, "Tassilo v. Parseval"
<tassilo.von.parseval@rwth-aachen.de> wrote:

>> I bet Larry Wall's life insurance premiums just skyrocketed. 
>
>It would, if anyone could take Xah Lee Loo seriously. But really, no one
>can. He's more like the court jester, creeping out of the dark every so
>and so months. We're all very much enjoying his sporadic shows. Really. 

Really!


Michele
-- 
you'll see that it shouldn't be so. AND, the writting as usuall is
fantastic incompetent. To illustrate, i quote:
- Xah Lee trolling on clpmisc,
  "perl bug File::Basename and Perl's nature"


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

Date: 30 Aug 2004 01:47:12 -0700
From: norman.werner@student.uni-magdeburg.de (norman werner)
Subject: Re: Larry Wall & Cults
Message-Id: <b301fb47.0408300047.3a8a77b1@posting.google.com>

> Well, let's see how your clear your mind was today.
> 
> Either it's a joke, in which case it is clear to all
> that it doesn't really mean troll, or it's not a joke
> in which case I obviously don't know Esperanto.
> 
>

I read it as an 'two-in-one'. 
A (not funny) joke about the troll and an infantile  sideremark about
eo spreading more half-truths.
"universal language" - Whats that? What is a universal language ...
Besides expressing basic wishes for  food, attention or love. And
where is/was the relation between the troll and eo?


> Here are the facts:
> 
> 1. It's a joke, as you surmised.
> 
> 2. I know Esperanto.

i read it _later_ . From youre joke it seemed more like you "heard of
esperanto".


So I hereby withdraw the accusation of stupidity - standing firm only
on the not-funny-front.



> Now can you perhaps see that your first comment in the poor
> translation of your own Esperanto is invalid and offensive?



Allright - it was not a translation - the error was to call it an
translation. But since only a extremly small minority of readers could
read both - it seemed  ok for me to change not the basic-message but
the way to express this message. E.g. I could not see the relevance
for a non-eo-speaker of eo having a x or not. So i changed this in the
"translation".

> By the way, to those not fluent in both languages, what this
> fellow really wrote was more along the lines of "Please do not
> joke about things you don't know about.  Xah Lee certainly --
> because Esperanto has no "x" -- is not Esperanto.  And your
> joke is merely stupid."

Yep. 

> 
> If you're going to accuse me of stupidity, please at least
> get your own translation and logic skills in working order
> first.

At least i was not the only who misunderstood you. 

And please; Since you elaborated on my "translation" - it's ok to
criticize.
But the same does not hold true for my logic-skill-malfunction - so
either do not diagnose it or elaborate more on it.


Norman


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

Date: 30 Aug 2004 05:26:50 -0700
From: genericax@hotmail.com (Sara)
Subject: Re: Parsing a text file into an array
Message-Id: <776e0325.0408300426.ed5e49e@posting.google.com>

sroth1979@hotmail.com (Scott) wrote in message news:<26dbb845.0408160912.6a549090@posting.google.com>...
> I having a bit of trouble trying to parse...
> 
> 789798798       test,test      12/5/3005
> 
> with tabs between each column. Does any one have some suggestions?

Sho nuff scooter..

  open F, $myFile;
  my @lines = <F>;
  close F;
  
  for (@lines)
    {my @line = split /\s+/; # assumes you have no whitespace in other fields
     # if you DO, then split on tabs explicitly
     # do what you want to do with this line
    }

 # take a break!


Cya,
G


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

Date: Sat, 28 Aug 2004 22:08:04 -0700
From: "Roman Rodriguez" <romanr@cablespeed.com>
Subject: passing arguments to subroutines
Message-Id: <jqmdnStgHvPZm67cRVn-ig@cablespeedwa.com>

Can anyone tell me if you can pass scalars and list to subroutines? if so,
what is the syntax? what am I doing wrong in the following code?
It seems the correct value is not returned because my subroutine doesn't
appear to be recieveing the parameter from the caller.


sub setMainMenuOption
{
    my $SelectedOption = $_;        #set $SelectedOption to value passed in
(from user)
    if( $SelectedOption eq 's')
    {
        return("Sleep");
    }
    return("INVALID");
{
$UserInput = "S\n"; #simulate STDIN user input of the capital letter 'S'
print "\n\$UserInput: $UserInput";

chomp($UserInput);
print "\n\$UserInput after CHOMP: $UserInput";

$UserInput = lc($UserInput);
print "\n\$UserInput after lc(): $UserInput";

$Menu = &setMainMenuOption($UserInput);
print "\n\$Menu after return = $Menu";

exit;

results in the following output:

$UserInput: S
$UserInput after CHOMP: S
$UserUnput after lc(): s
$Menu after return = INVALID

when I step through this code I see that "$_" in the subroutine is not
properly recieving the arguement and therefore variable $SelectedOption is
remaining as "".
what is the proper way to pass arguments to a subroutine?

Thanks!
-RR



Thanks
-RR




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

Date: Mon, 30 Aug 2004 12:53:34 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: passing arguments to subroutines
Message-Id: <2pgfkhFka6n0U1@uni-berlin.de>

Roman Rodriguez wrote:
> Can anyone tell me if you can pass scalars and list to subroutines?

You can.

> if so, what is the syntax?

It's described in "perldoc perlsub".

> what am I doing wrong in the following code?

Arguments that are passed to a sub are available within the sub in @_, 
not in $_.

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 30 Aug 2004 12:58:28 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: passing arguments to subroutines
Message-Id: <Xns9555847D12F78elhber1lidotechnet@62.89.127.66>

"Roman Rodriguez" <romanr@cablespeed.com> wrote:

> Can anyone tell me if you can pass scalars and list to
> subroutines? if so, what is the syntax? what am I doing wrong in
> the following code? It seems the correct value is not returned
> because my subroutine doesn't appear to be recieveing the
> parameter from the caller. 
> 
> 
> sub setMainMenuOption
> {
>     my $SelectedOption = $_;        #set $SelectedOption to value
                           ^^^

That should be $_[0]. All arguments passed to the subroutine are stored 
in the special array @_. Read more about it by doing


  perldoc perlsub


-- 
Cheers,
Bernard


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

Date: Mon, 30 Aug 2004 13:43:07 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: passing arguments to subroutines
Message-Id: <cgv3lh$7od$1@nntp.fujitsu-siemens.com>

Roman Rodriguez wrote:
> Can anyone tell me if you can pass scalars and list to subroutines? if =
so,
> what is the syntax? what am I doing wrong in the following code?
> It seems the correct value is not returned because my subroutine doesn'=
t
> appear to be recieveing the parameter from the caller.
>=20
>=20
> sub setMainMenuOption
> {
>     my $SelectedOption =3D $_;        #set $SelectedOption to value pas=
sed in
> (from user)
>     if( $SelectedOption eq 's')
>     {
>         return("Sleep");
>     }
>     return("INVALID");
> {
   ^
This should be a right curly!

> $UserInput =3D "S\n"; #simulate STDIN user input of the capital letter =
'S'
> print "\n\$UserInput: $UserInput";
>=20
> chomp($UserInput);
> print "\n\$UserInput after CHOMP: $UserInput";
>=20
> $UserInput =3D lc($UserInput);
> print "\n\$UserInput after lc(): $UserInput";
>=20
> $Menu =3D &setMainMenuOption($UserInput);
> print "\n\$Menu after return =3D $Menu";
>=20
> exit;
>=20
> results in the following output:

No it does not!

> $UserInput: S
There should be an empty line here
> $UserInput after CHOMP: S
> $UserUnput after lc(): s
> $Menu after return =3D INVALID

Not that it matters in this case, because the answer to the question was =

very obvious, but the incorrect reproduction of the source and the=20
results may confuse people who are willing to help!

Best to use copy-and-paste when posing code and results rather than=20
typing them in.

--=20
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize
						-- T.  Pratchett



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

Date: 29 Aug 2004 20:52:01 -0700
From: srigowrisn@hotmail.com (shree)
Subject: Re: perl - data structure build to transpose data
Message-Id: <49b5740e.0408291952.1e38f617@posting.google.com>

anno4000@lublin.zrz.tu-berlin.de (Anno Siegel) wrote in message news:<cgtifu$44j$1@mamenchi.zrz.TU-Berlin.DE>...
> shree <srigowrisn@hotmail.com> wrote in comp.lang.perl.misc:
> > Hi,
> > 
> > I have been asked to transpose a data file extracted from an Excel
> > report and saved as a .txt file. It lists time (MonthYear) in the
> > header (first row). The data consists of blocks of 3 lines per
> > supplier. In the example extract shown below, for Jan-04, total items
> > supplied by supplier 1 were 1000, of which there were 200 defects,
> > giving a defect ratio of 20%. I need to read-in this data file and
> > output a file whose format I can best illustrate via an example shown
> > below. Please note in the outfile's last column, it shows MonthID. If
> > the data were to begin with Feb-04 and go till July-04, instead of
> > Jan-04 to Mar-04 as shown below, then Feb-04 would be 1, Mar-04 2 and
> > so on.
> > 
> > Anyway, I'm struggling on thoughts of how to build a data structure to
> > transform the data into the desired output file. Any pointers, code
> > snippets will be greatly appreciated and I thank you in advance.
> 
> It would be nice to see a snippet of your code, or even of your
> thoughts about the problem.  Just dumping the problem description
> *you* got to the newsgroup is frowned upon.  You haven't even begun
> an analysis.
> 
> > Sample Data filein.dat
> > 	 	Jan-04	Feb-04	Mar-04
> > Supp1	%	20.00%	10.17%	7.14%
> > 	Defects	200	122	100
> > 	Total	1000	1200	1400
> > Supp2	%	3.00%	1.82%	1.90%
> > 	Defects	60	40	40
> > 	Total	2000	2200	2100
> 
> So the first data line is special and gives you the months to expect.
> Assuming the data in DATA, get the list of months and generate the
> MonthID's like this (all untested):
> 
>     my ( @months, %month_id);
>     @months = split for ( scalar <DATA> );
>     @month_id{ @months} = 1 .. @months;
> 
> Also set an output format at this point, you'll need it later:
> 
>     my $ofmt = "%-5s %-7s %-7s %-6s %2d\n";
> 
> You can save yourself the effort of setting this up and use my
> module Text::Table instead, but the format will do.
> 
> Now you can process the following lines in groups of three:
> 
>     line: while ( 1 ) {
>         my ( $supp, %supp_data);
>         for ( scalar <DATA> ) { # get one line in $_
>             last line unless defined; # regular end of file
>             ( $supp, undef, @{ $supp_data{ '%'}}{ @months}) = split;
>         }
>         for ( scalar <DATA> ) {
>             die "data error 2" unless defined;
>             ( undef, @{ $supp_data{ Defects}}{ @months}) = split;
>         }
>         for ( scalar <DATA> ) {
>             die "data error 3" unless defined;
>             ( undef, @{ $supp_data{ Total}}{ @months}) = split;
>         }
> 
> There should probably be data checks in a real program, besides the
> end-of-file test I provided.  Anyway, now you have collected all data
> for one supplier and can print it in any format you want, for instance
> this:
> 
>         for my $month ( @months) {
>             for ( qw( % Defects Total) ) {
>                 printf $ofmt, $supp, $_, $supp_data{ $_}->{ $month},
>                     $month, $month_id{ $month};
>             }
>         }
>     }
> 
> 
> > Desired Ouput file out.txt				
> 
> [snipped]
> 
> Anno

Hello All,

Let me first begin with saying a big 'thank you' to all and I really
appreciate your help and the time you took. I tried out the examples
you guys shared and every one of them gave the expected result. I
apologize for not posting my attempts earlier primarily because I felt
I was clueless.

I was wondering if anyone can suggest a perl book or website thats
filled with illustrative examples of problems involving complex data
structures. To me, this is the hardest concept to grasp.

Thank you,
Shree


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

Date: Mon, 30 Aug 2004 06:28:03 GMT
From: "John W. Krahn" <someone@example.com>
Subject: Re: perl - data structure build to transpose data
Message-Id: <TNzYc.74016$X12.49488@edtnps84>

[ please do not top-post.  TIA ]

shree wrote:
> 
> I was wondering if anyone can suggest a perl book or website thats
> filled with illustrative examples of problems involving complex data
> structures. To me, this is the hardest concept to grasp.

You should probably check out this book and see if it meets your requirements:
http://www.oreilly.com/catalog/maperl/index.html


John
-- 
use Perl;
program
fulfillment


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

Date: 30 Aug 2004 09:11:53 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl and memory
Message-Id: <cgur0p$psm$2@mamenchi.zrz.TU-Berlin.DE>

Marcus <mygooglegroupsaccount@yahoo.com> wrote in comp.lang.perl.misc:
> Im sitting with fairly big perl scripts that I now need to optimize to
> make them less resource intensive for the server.
> 
> If someone could provide some general guidelines in this, that would
> be much appreciated.

You ask for advice and you're not even saying *what* resources you
want to optimize.  That is ridiculous.

What is the program doing, and in what way is it tasking the server's
resources?  That is the minimum info needed to even begin answering
your question.

Anno


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

Date: Mon, 30 Aug 2004 15:18:21 +0800
From: Jason Quek <qjason@starhub.net.sg>
Subject: Reading Unicode File and Saving Contents to Access
Message-Id: <eek5j01vmuq0rmtgjcu8ka26o1um9r2gor@4ax.com>

Hi

I have a Unicode (utf8) file containing Unicode characters. I need to
open this file, read each line, then save it to an Access database
table via SQL.

This is my script:

#--------------------------------------------------
$file = 'unicode.txt';
open (FILE, "$file") || print "cannot open $file: $!";
while (<FILE>)
	{
	$name = $_;

	$sql = "INSERT INTO `sql_table` VALUES ('$name')";
	&execute_sql;
	}
#--------------------------------------------------

However, what gets inserted into the Access table does not match the
original characters.

What am I doing wrong, and what is the correct way to read the Unicode
file and save the contents?

I have looked at the "Unicode::String" module, but am not sure how to
use it in my case.

Any help would be appreciated.

Thank you and regards,



Jason Q.


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

Date: Mon, 30 Aug 2004 08:13:25 +0200
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: Reference to functions
Message-Id: <Xns955554294CF09elhber1lidotechnet@62.89.127.66>

Brian McCauley <nobull@mail.com> wrote:

> Bernard El-Hagin wrote:
> 
>> "Paul Lalli" <mritty@gmail.com> wrote:
>> 
>>>You don't.  That's specifically the kind of thing use strict;
>>>exists to prevent. [...]
>> 
>> It's *one of several* kinds of things use strict exists to prevent. 
>> Not a nitpick. That kind of statement would have confused me to no 
>> end back when I was starting out with Perl. :)
> 
> [ Your smiley has no nose, how does it smell?... ]
> 
> Not to nitpick but strict prevents 3 kinds of things and I've always 
> considered "several" to start not lower than 4.  :-)


Your smiley has no nostrils, how does it smell? ;-)


-- 
Cheers,
Bernard


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

Date: 30 Aug 2004 00:15:59 -0700
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Re: Removing entries in array based on another array
Message-Id: <cguk7f$i7v@odah37.prod.google.com>

Thanks! But that's not exactly what I want to do. I would like to do
@array1 minus @array2, not intersection or difference. However, I'll
look thru the code and try to figure it how to do what I want. I guess
the trick is to push elements not found in @array2 on to a new array.
Leif



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

Date: 30 Aug 2004 01:04:54 -0700
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Re: Removing entries in array based on another array
Message-Id: <cgun36$7s0@odbk17.prod.google.com>

I can't figure it out:

use strict;
use warnings;

my @names  ("bob","barney","-","lisa","UNKNOWN");
my @delete ("-","unknown");
my @res = ();
foreach $element (@names) {
if (!defined $delete[$element]) {
push @res, $element;
}
}

It almost work. However, "UNKNOWN" is still in @res. And how do i put
this code in a function? Is it possible to have two arrays as input to
a function?

Leif



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

Date: 30 Aug 2004 09:05:34 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Removing entries in array based on another array
Message-Id: <cguqku$psm$1@mamenchi.zrz.TU-Berlin.DE>

Leif Wessman <leifwessman@hotmail.com> wrote in comp.lang.perl.misc:
> Thanks! But that's not exactly what I want to do.

What is?  Give some context.  And, while you're at it, persuade
your news reader to post real follow-ups.

>                                                   I would like to do
> @array1 minus @array2, not intersection or difference.

How are your "minus" and the faq's "difference", umm, different?

Anno


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

Date: 30 Aug 2004 02:18:01 -0700
From: "Leif Wessman" <leifwessman@hotmail.com>
Subject: Re: Removing entries in array based on another array
Message-Id: <cgurc9$a5@odah37.prod.google.com>

my @names ("bob","barney","-","lisa","UNKNOWN");
my @delete ("-","unknown","n/a");

@names minus @delete ==> "bob", "barney", "lisa"
@names diff @delete ==> "bob", "barney", "lisa", "n/a"



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

Date: Mon, 30 Aug 2004 11:38:12 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Removing entries in array based on another array
Message-Id: <2pgb6aFjn9q8U1@uni-berlin.de>

Leif Wessman wrote:
> I can't figure it out:
> 
> use strict;
> use warnings;
> 
> my @names  ("bob","barney","-","lisa","UNKNOWN");
> my @delete ("-","unknown");
> my @res = ();
> foreach $element (@names) {
> if (!defined $delete[$element]) {
> push @res, $element;
> }
> }

The above code does not compile. When posting code, please copy rather
than retype it. Also, use indenting for readability.

> It almost work.

For an odd definition of "almost", then. For me, after correcting the
typos, your code generates a bunch of warnings, and @res is empty.

To access an array element, you use the index number. The numerical
value of a non-numerical string is 0, so your code repeatedly tests
whether the first element in @delete is defined. Since it is, @res
never gets populated.

You need to start reading:
http://www.perldoc.com/perl5.8.4/pod/perlintro.html

> However, "UNKNOWN" is still in @res.

No, it's not. But I take it that you want to compare the strings case
insensitively.

> And how do i put this code in a function? Is it possible to have
> two arrays as input to a function?

Yes. http://www.perldoc.com/perl5.8.4/pod/perlsub.html

This is a possible solution:

     sub unique {
         my %del = map { lc $_, 1 } @{$_[1]};
         grep !$del{ lc $_ }, @{$_[0]}
     }

     my @res = unique( \@names, \@delete );

(I did not follow the FAQ entry. Instead I chose the approach to
populate a hash with the elements in @delete as the keys.)

-- 
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl


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

Date: Mon, 30 Aug 2004 14:41:32 +0200
From: "Trond Michelsen" <trondmm-usenet@crusaders.no>
Subject: Using SSL certificates with LWP
Message-Id: <cgv79m$m78$1@services.kq.no>

Hi.

I'm making a module that needs to make RPC calls to a secure HTTP-server
using SSL certificates.
I'm using Crypt::SSLeay right now, and everything is working fine. It's just
that as far as I can tell, the only way to use the certificates with
Crypt::SSLeay, is to set the full path to them in environment variables, and
I'm a bit uncomfortable with that. Is there any way to tell LWP which
certificates it should use directly?

Or should I just do local %ENV and set the certificates just before I call
$ua->request()?

-- 
Trond Michelsen




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

Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>


Administrivia:

#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc.  For subscription or unsubscription requests, send
#the single line:
#
#	subscribe perl-users
#or:
#	unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.

#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.

#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.


------------------------------
End of Perl-Users Digest V10 Issue 6932
***************************************


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