[29851] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1094 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Dec 6 16:33:35 2007

Date: Thu, 6 Dec 2007 13:09:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 6 Dec 2007     Volume: 11 Number: 1094

Today's topics:
        Adding style attribute to <body> tag using CGI.pm malatinszky@gmail.com
    Re: Adding style attribute to <body> tag using CGI.pm <kingskippus@gmail.com>
    Re: Adding style attribute to <body> tag using CGI.pm malatinszky@gmail.com
        allow potential special characters '@' and '$' in syste wong_powah@yahoo.ca
    Re: allow potential special characters '@' and '$' in s <glex_no-spam@qwest-spam-no.invalid>
    Re: allow potential special characters '@' and '$' in s <spamtrap@dot-app.org>
    Re: Better way to invoke dynamic function? <tzz@lifelogs.com>
    Re: Building a hash map out of two arrays malatinszky@gmail.com
    Re: Building a hash map out of two arrays <uri@stemsystems.com>
        Code reuse without inheritance? <socyl@987jk.com.invalid>
        crontab script <gabrielepetrone@gmail.com>
    Re: crontab script <kingskippus@gmail.com>
    Re: FAQ 4.69 How can I use a reference as a hash key? (Steven M. O'Neill)
    Re: how check new URL of redirected page <tzz@lifelogs.com>
    Re: how check new URL of redirected page <ben@morrow.me.uk>
        Multi phase processing <daves@orpheusmail.co.uk>
    Re: Multi phase processing <thepoet_nospam@arcor.de>
    Re: Nested sorting of a hash <justin.0711@purestblue.com>
    Re: Nested sorting of a hash <glennj@ncf.ca>
    Re: Nested sorting of a hash <jurgenex@hotmail.com>
    Re: Nested sorting of a hash <bugbear@trim_papermule.co.uk_trim>
    Re: Nested sorting of a hash <glennj@ncf.ca>
    Re: Nested sorting of a hash <jurgenex@hotmail.com>
    Re: Nested sorting of a hash <uri@stemsystems.com>
        New version of Config::Model (v0.616): INI file support <dominique.dumont@hp.com>
        sprintf or format <joey.foley@gmail.com>
        Tk Optionmenu foreground colors <glgas@aim.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 6 Dec 2007 11:10:24 -0800 (PST)
From: malatinszky@gmail.com
Subject: Adding style attribute to <body> tag using CGI.pm
Message-Id: <57afe709-2e95-4386-b386-1665cf0317d9@w34g2000hsg.googlegroups.com>

I am using the standard CGI module to output a HTML document. I would
like the <body> tag of the HTML doc to have a style attribute, like
this:

<body style="margin-left:5px;">

My thought was to writ

print $q->start_html(-style=>"margin-left:5px;");

but if I do that, what I get is

<link rel="stylesheet" type="text/css" href="margin-left:5px;" />

because -style is used as a shortcut to attach a style sheet.

How do I do this right?

Thanks,

Andras Malatinszky


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

Date: Thu, 6 Dec 2007 12:01:21 -0800 (PST)
From: TonyV <kingskippus@gmail.com>
Subject: Re: Adding style attribute to <body> tag using CGI.pm
Message-Id: <c302edc5-653a-4dc3-9da0-a9558b5b5b1c@e1g2000hsh.googlegroups.com>

On Dec 6, 2:10 pm, malatins...@gmail.com wrote:
> I am using the standard CGI module to output a HTML document. I would
> like the <body> tag of the HTML doc to have a style attribute, like
> this:
>
> <body style="margin-left:5px;">
>
> My thought was to writ
>
> print $q->start_html(-style=>"margin-left:5px;");
>
> but if I do that, what I get is
>
> <link rel="stylesheet" type="text/css" href="margin-left:5px;" />
>
> because -style is used as a shortcut to attach a style sheet.
>
> How do I do this right?
>
> Thanks,
>
> Andras Malatinszky

Wow, I've never really thought about that before.  I don't know what
the answer is, but here's a possible workaround:

print $q->start_html(-style=>{ -code=>"body: { margin-left:5px; }" });

This will attach a style to the body element in the page's header.


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

Date: Thu, 6 Dec 2007 12:18:45 -0800 (PST)
From: malatinszky@gmail.com
Subject: Re: Adding style attribute to <body> tag using CGI.pm
Message-Id: <5b1cfb6f-1979-4815-9e83-d9630921a0cb@s19g2000prg.googlegroups.com>

On Dec 6, 3:01 pm, TonyV <kingskip...@gmail.com> wrote:
> On Dec 6, 2:10 pm, malatins...@gmail.com wrote:
>
>
>
> > I am using the standard CGI module to output a HTML document. I would
> > like the <body> tag of the HTML doc to have a style attribute, like
> > this:
>
> > <body style="margin-left:5px;">
>
> > My thought was to writ
>
> > print $q->start_html(-style=>"margin-left:5px;");
>
> > but if I do that, what I get is
>
> > <link rel="stylesheet" type="text/css" href="margin-left:5px;" />
>
> > because -style is used as a shortcut to attach a style sheet.
>
> > How do I do this right?
>
> > Thanks,
>
> > Andras Malatinszky
>
> Wow, I've never really thought about that before.  I don't know what
> the answer is, but here's a possible workaround:
>
> print $q->start_html(-style=>{ -code=>"body: { margin-left:5px; }" });
>
> This will attach a style to the body element in the page's header.

Thank you.


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

Date: Thu, 6 Dec 2007 08:32:03 -0800 (PST)
From: wong_powah@yahoo.ca
Subject: allow potential special characters '@' and '$' in system call
Message-Id: <3441fb95-6f6c-4d16-84e0-9faff9296d9c@i12g2000prf.googlegroups.com>

I want to change a system call to allow potential special characters
'@' and '$'.
This work for regular character in  $PASSWORD.
$rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p $PASSWORD
1>login.out 2>login.err");
How to change it to a form that allow potential special characters '@'
and '$' in $PASSWORD?

I tried this, but it does not work:
$rc = system "/usr/lunasa/bin/salogin", "-i 1234:5678 -s 3 -o -p
$PASSWORD 1>salogin.out 2> salogin.err";

print "rc $rc";

rc 65280


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

Date: Thu, 06 Dec 2007 10:43:07 -0600
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: allow potential special characters '@' and '$' in system call
Message-Id: <4758269b$0$505$815e3792@news.qwest.net>

wong_powah@yahoo.ca wrote:
> I want to change a system call to allow potential special characters
> '@' and '$'.
> This work for regular character in  $PASSWORD.
> $rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p $PASSWORD
> 1>login.out 2>login.err");
> How to change it to a form that allow potential special characters '@'
> and '$' in $PASSWORD?
> 
> I tried this, but it does not work:
> $rc = system "/usr/lunasa/bin/salogin", "-i 1234:5678 -s 3 -o -p
> $PASSWORD 1>salogin.out 2> salogin.err";
> 
> print "rc $rc";
> 
> rc 65280

$rc = system "/usr/lunasa/bin/salogin -i 1234:5678 -s 3 -o -p 
\"$PASSWORD\" 1>salogin.out 2> salogin.err";


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

Date: Thu, 06 Dec 2007 13:02:30 -0500
From: Sherman Pendley <spamtrap@dot-app.org>
Subject: Re: allow potential special characters '@' and '$' in system call
Message-Id: <m1prxjaeh5.fsf@dot-app.org>

wong_powah@yahoo.ca writes:

> I want to change a system call to allow potential special characters
> '@' and '$'.
> This work for regular character in  $PASSWORD.
> $rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p $PASSWORD
> 1>login.out 2>login.err");
> How to change it to a form that allow potential special characters '@'
> and '$' in $PASSWORD?

Most shells have the same interpolation rules as Perl - in fact, that's
where Perl borrowed its rules from. So if you want to allow this, you'll
need to use single quotes around that parameter:

    $rc = system("/usr/local/bin/mylogin -i 1234:5678 -s 3 -o -p
    '$PASSWORD' 1>login.out 2>login.err");

> I tried this, but it does not work:
> $rc = system "/usr/lunasa/bin/salogin", "-i 1234:5678 -s 3 -o -p
> $PASSWORD 1>salogin.out 2> salogin.err";

I wouldn't expect it to work - you're trying to redirect stdout and stderr,
which would require the command to be parsed by a shell interpreter. But,
the multi-argument form of system() bypasses the shell and directly runs
specified program. Also, the multi-argument form doesn't split its args,
so the above will run the salogin command and pass that whole string as
its first parameter - including the spaces.

If you didn't need to redirect stdout and stderr, you could use the multi-
argument form of system(), thereby avoiding the need to worry about shell
interpolation and the need to escape shell metacharacters:

    $rc = system('/usr/local/bin/mylogin', '-i', '1234:5678', '-s', '3',
    '-o', '-p', $PASSWORD);

> print "rc $rc";
>
> rc 65280

Note that the return value from system() is not just the exit code from
mylogin - it's that, plus some other information. To properly handle it,
you need to use this snippet of code, taken from "perldoc -f system":

    You can check all the failure possibilities by inspecting $?
    like this:
    
        if ($? == -1) {
           print "failed to execute: $!\n";
        }
        elsif ($? & 127) {
           printf "child died with signal %d, %s coredump\n",
               ($? & 127),  ($? & 128) ? 'with' : 'without';
        }
        else {
           printf "child exited with value %d\n", $? >> 8;
        }
    
sherm--

-- 
WV News, Blogging, and Discussion: http://wv-www.com
Cocoa programming in Perl: http://camelbones.sourceforge.net


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

Date: Thu, 06 Dec 2007 08:31:06 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: Better way to invoke dynamic function?
Message-Id: <86mysnopxx.fsf@lifelogs.com>

On Thu, 06 Dec 2007 03:16:31 GMT Uri Guttman <uri@stemsystems.com> wrote: 

>>>>>> "h" == howa  <howachen@gmail.com> writes:
h> Uri Guttman 寫道:

>>> >>>>> "h" == howa  <howachen@gmail.com> writes:
>>> 
>>> 
h> The function name is unknown at runtime, it is input by user.
>>> 
>>> that is a VERY bad idea. why do newbies always think allowing users to
>>> input a function name is a good idea?
>>> 

h> each time user add a new function, you would need to modify the
h> dispatch table, which might lead to error.

UG> gack!! you have users adding functions?? you want that or users calling
UG> anything in your system vs. adding an entry into a dispatch table? i
UG> give up.

Well hang on, let's not make so many assumptions.  Maybe there's a
legitimate reason for howa's need.  We should find out what's really
going on.

howa, what are users really selecting through this function?  Is it a
loadable module you provide, or is it a function they define for an API
your software provides?  How was it done before you used Perl, if at all?

Ted


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

Date: Thu, 6 Dec 2007 11:13:58 -0800 (PST)
From: malatinszky@gmail.com
Subject: Re: Building a hash map out of two arrays
Message-Id: <8fdb8360-37db-4a8b-9ccc-be7c5bc52af6@x69g2000hsx.googlegroups.com>

On Dec 6, 6:56 am, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Kira Yamato <kira...@earthlink.net>:
>
> > Suppose you have two arrays
>
> > my @keys = qw/ a b c d /;
> > my @values = ( 1, 2, 3, 4 );
>
> > Does anyone know a slick way of building a hash with @keys and @values?
>
>     my %hash;
>     @hash{ @keys } = @values;
>
>
> Ben

That's probably as slick as it gets.


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

Date: Thu, 06 Dec 2007 19:55:22 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Building a hash map out of two arrays
Message-Id: <x7tzmvoaxi.fsf@mail.sysarch.com>

>>>>> "m" == malatinszky  <malatinszky@gmail.com> writes:

  m> On Dec 6, 6:56 am, Ben Morrow <b...@morrow.me.uk> wrote:
  >> Quoth Kira Yamato <kira...@earthlink.net>:
  >> 
  >> > Suppose you have two arrays
  >> 
  >> > my @keys = qw/ a b c d /;
  >> > my @values = ( 1, 2, 3, 4 );
  >> 
  >> > Does anyone know a slick way of building a hash with @keys and @values?
  >> 
  >> my %hash;
  >> @hash{ @keys } = @values;

  m> That's probably as slick as it gets.

i wouldn't call using slices a slick trick. see more in my slices
tutorial:

	http://sysarch.com/Perl/hash_slice.txt

as for slick, i like this trick but it will destroy one of the
arrays. and it allows for the hash declare in the same statement.
(you can choose which array to destroy):

my %hash = map { $_ => shift @values } @keys ;
my %hash = map { shift @keys => $_ } @values ;

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 6 Dec 2007 21:06:15 +0000 (UTC)
From: kj <socyl@987jk.com.invalid>
Subject: Code reuse without inheritance?
Message-Id: <fj9o87$cqk$1@reader1.panix.com>





OK, there's this module XYZ (say, downloaded from CPAN), that is
*almost* perfectly fits my needs.  Furthermore, all it would take
to make this fit perfect amounts to changing a couple of lines of
code in some ubiquitously used internal sub, XYZ::_pesky.  Assume
that, for whatever reason, this is not a change that the author of
XYZ.pm would make.

What's a programmer to do?  The most expedient workaround, of
course, would be to simply copy the contents of XYZ.pm to a new
file, give it a different name, and modify this clone to my heart's
content.  But this sort of cut-and-paste programming is notoriously
problematic.  For one thing, it would have to be repeated everytime
XYZ.pm is updated (assuming we want to remain always at the bleeding
edge of XYZ-tude).  Plus, I feel queasy about lifting a fellow
programmer's work wholesale like that.  (And here I'm completely
setting aside legal issues regarding intellectual property, licensing,
etc.)

An alternative to wholesale cut-and-paste would be to redefine the
function in question in my own code:

  use XYZ ':all';

  {
    package XYZ;
    no warnings 'redefine';
    sub _pesky {
      # ...
    }
  }

This approach may be a bit less of a chore when XYZ gets updated,
but it's still prety fragile.  Plus, it doesn't work so well when
the function to be redesigned needs to access lexically-scoped data
in XYZ.pm.  And, even when such redefinition is workable, it goes
too far, because it changes the behavior of XYZ everywhere; if some
other module we use happens to use XYZ, such redefinition is likely
to backfire on us...

Before I go off implementing some utterly insane scheme involving
File::Slurp, s///, and eval I thought I'd ask here if there's a
halfway decent "best practice" in these situations.

TIA!

kj

-- 
NOTE: In my address everything before the first period is backwards;
and the last period, and everything after it, should be discarded.


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

Date: Thu, 6 Dec 2007 10:52:16 -0800 (PST)
From: Manuel <gabrielepetrone@gmail.com>
Subject: crontab script
Message-Id: <425d4a9d-6518-432d-adf7-efe92988232a@e25g2000prg.googlegroups.com>

Hello,
i was trying to create a script that checks if internet connection and
if it is off the perl script tries to connect again and lunch a perl
script.
it opens a txt file, get the timestamp. in $differenza i get the
difference between now and the timestamp in the txt file (in this file
i write with blog.pl the operation time timestamp ). if the difference
is more than 10000 seconds it means the connection is off so it tries
to connect again. and if the difference is more than 500 it start the
blog.pl process again. i did put this file in the crontab list:
 */1 * * * * perl /home/user/perl/crontab.pl
but the blog.pl never stars. Why???


 this is the code of crontab.pl:

$ora_aggiornata=time();
open (CHECKBOOK, "timestamp.txt");
$timestamp = <CHECKBOOK>;
$differenza=$ora_aggiornata-$timestamp;
print "$differenza\n";
if ($differenza > 10000){
$ifc=`ifconfig | grep P-t-P`;
 if ($ifc eq "") {
     `poff dsl-provider`;
      `sleep 1`;
     `pon dsl-provider`;
 }
}
if ($differenza > 500) {
       exec("perl blog.pl &");
} else {
	print "no not yet\n";

}


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

Date: Thu, 6 Dec 2007 11:36:42 -0800 (PST)
From: TonyV <kingskippus@gmail.com>
Subject: Re: crontab script
Message-Id: <4537bee5-5f64-4df2-bed4-6ed96acc9cbc@n20g2000hsh.googlegroups.com>

On Dec 6, 1:52 pm, Manuel <gabrielepetr...@gmail.com> wrote:
> Hello,
> i was trying to create a script that checks if internet connection and
> if it is off the perl script tries to connect again and lunch a perl
> script.
> it opens a txt file, get the timestamp. in $differenza i get the
> difference between now and the timestamp in the txt file (in this file
> i write with blog.pl the operation time timestamp ). if the difference
> is more than 10000 seconds it means the connection is off so it tries
> to connect again. and if the difference is more than 500 it start the
> blog.pl process again. i did put this file in the crontab list:
>  */1 * * * * perl /home/user/perl/crontab.pl
> but the blog.pl never stars. Why???
>
>  this is the code of crontab.pl:
>
> $ora_aggiornata=time();
> open (CHECKBOOK, "timestamp.txt");
> $timestamp = <CHECKBOOK>;
> $differenza=$ora_aggiornata-$timestamp;
> print "$differenza\n";
> if ($differenza > 10000){
> $ifc=`ifconfig | grep P-t-P`;
>  if ($ifc eq "") {
>      `poff dsl-provider`;
>       `sleep 1`;
>      `pon dsl-provider`;
>  }}
>
> if ($differenza > 500) {
>        exec("perl blog.pl &");} else {
>
>         print "no not yet\n";
>
> }

I might be wrong, but I would guess that the crontab.pl process is
dying before the blog.pl process completes.

Have you considered using system() or backticks instead of exec()?
What happens if you put a print "in blog.pl"; statement at the
beginning of blog.pl, does it print?


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

Date: Thu, 6 Dec 2007 18:04:07 +0000 (UTC)
From: steveo@panix.com (Steven M. O'Neill)
Subject: Re: FAQ 4.69 How can I use a reference as a hash key?
Message-Id: <fj9din$6s3$1@reader1.panix.com>

PerlFAQ Server  <brian@stonehenge.com> wrote:
>--------------------------------------------------------------------
>
>4.69: How can I use a reference as a hash key?
>
>    (contributed by brian d foy)
>
>    Hash keys are strings, so you can't really use a reference as the key.
>    When you try to do that, perl turns the reference into its stringified
>    form (for instance, "HASH(0xDEADBEEF)"). 

Moo!

-- 
Steven O'Neill                                  steveo@panix.com
Brooklyn, NY                        http://www.panix.com/~steveo


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

Date: Thu, 06 Dec 2007 08:33:02 -0600
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: how check new URL of redirected page
Message-Id: <86ir3bopup.fsf@lifelogs.com>

On Thu, 6 Dec 2007 02:53:01 +0100 "Petr Vileta" <stoupa@practisoft.cz> wrote: 

PV> HTML::Parser is "too big gun to small rabbit" :-) For meta element
PV> base redirections is successful some like this

PV> # I precede that html page is in variable $content
PV> $content=~s/^.?(<meta\s+?HTTP-EQUIV=.REFRESH..+?>).+$/$1/si;
PV> $content=~s/^.+?url=(.+?)[\'\">]

PV> Now $content contain new URL.

This is like using garrote wire to catch and strangle the rabbit :)

Ted


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

Date: Thu, 6 Dec 2007 15:17:17 +0000
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: how check new URL of redirected page
Message-Id: <tcgl25-uba.ln1@osiris.mauzo.dyndns.org>


Quoth "Petr Vileta" <stoupa@practisoft.cz>:
> Sorry Ben, please do not kill me, but HTML::Parser is "too big gun to small 
> rabbit" :-)
> For meta element base redirections is successful some like this
> 
> # I precede that html page is in variable $content

my $content = <<HTML;
<html>
    <head>
        <!-- <meta HTTP-EQUIV="REFRESH" url="some/fake/url"> -->
        <  META content=10;url=foo http-equiv=refresh>
    </head>
    <body>
        Hello world!
    </body>
</html>
HTML

> $content=~s/^.?(<meta\s+?HTTP-EQUIV=.REFRESH..+?>).+$/$1/si;
> $content=~s/^.+?url=(.+?)[\'\">]

This line is not valid Perl.

> Now $content contain new URL.

No, it doesn't.

LWP::UserAgent will parse the <head> section of a text/html document for
you, and return the http-equiv headers in with the real HTTP headers.
For this purpose it uses HTML::HeadParser, which, guess what, is a
subclass of HTML::Parser. This means that a refresh can be detected with

    $response->header('refresh');

Ben



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

Date: Thu, 6 Dec 2007 09:41:22 -0800 (PST)
From: Dave <daves@orpheusmail.co.uk>
Subject: Multi phase processing
Message-Id: <c881c201-5df4-4e39-9235-1bf47b6e389b@y43g2000hsy.googlegroups.com>

Hi folks,

I writing a perl/mysql backend to a website, part of which takes a
number of pages of input, then, at the end, stores all the info on the
database. Since Apache is stateless, all the data input from previous
pages has to be put back into the next page in the form of hidden
input tags, and then read back in each time. This is a touch long
winded, but for most of the data works fine. I have however hit a snag
with 1 set of data that is made up of a repeating set of which any
number (or none) may be selected.

This data is a set of dynamically generated tick boxes of related
data, all of which is taken from some data tables on the database. For
example, if the page was asking which languages a person programmes
in, it would then offer a list of choices from the database which the
end user selects from. Part of the problem is that it also lists 3
separate options against each, for example used on VME, Windows,
Linux.

The end result would look something like this, where each '@' is a
separate input type="checkbox" html tag:

Language           VME       Windows      Linux
Application Master  @           @           @
C                   @           @           @
Cobol               @           @           @
Perl                @           @           @
SCL                 @           @           @

The idea being that if someone has programmed in Cobol on VM, and in
Perl on Windows and Linux the appropriate boxes are ticked. The
validation is fun because in the above, cut down, example, Application
master and SCL are only available on VME, and Perl is the only one not
available on VME. The other two being available on all platforms.

Where this is the only page, so that all the info is input in one go,
I have no problems. Where I have a problem, is holding this in
temporary input type = "hidden" tags within the html page. Does anyone
have any suggestions on the best way to hold this data?

I hope all this makes sense.

Many thanks,

Dave


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

Date: Thu, 06 Dec 2007 19:34:22 +0100
From: Christian Winter <thepoet_nospam@arcor.de>
Subject: Re: Multi phase processing
Message-Id: <47583f33$0$16573$9b4e6d93@newsspool1.arcor-online.net>

Dave schrieb:
> Hi folks,
> 
> I writing a perl/mysql backend to a website, part of which takes a
> number of pages of input, then, at the end, stores all the info on the
> database. Since Apache is stateless, all the data input from previous
> pages has to be put back into the next page in the form of hidden
> input tags, and then read back in each time. This is a touch long
> winded, but for most of the data works fine. I have however hit a snag
> with 1 set of data that is made up of a repeating set of which any
> number (or none) may be selected.
> 
> This data is a set of dynamically generated tick boxes of related
> data, all of which is taken from some data tables on the database. For
> example, if the page was asking which languages a person programmes
> in, it would then offer a list of choices from the database which the
> end user selects from. Part of the problem is that it also lists 3
> separate options against each, for example used on VME, Windows,
> Linux.
> 
> The end result would look something like this, where each '@' is a
> separate input type="checkbox" html tag:
> 
> Language           VME       Windows      Linux
> Application Master  @           @           @
> C                   @           @           @
> Cobol               @           @           @
> Perl                @           @           @
> SCL                 @           @           @
> 
> The idea being that if someone has programmed in Cobol on VM, and in
> Perl on Windows and Linux the appropriate boxes are ticked. The
> validation is fun because in the above, cut down, example, Application
> master and SCL are only available on VME, and Perl is the only one not
> available on VME. The other two being available on all platforms.
> 
> Where this is the only page, so that all the info is input in one go,
> I have no problems. Where I have a problem, is holding this in
> temporary input type = "hidden" tags within the html page. Does anyone
> have any suggestions on the best way to hold this data?

As you're asking for the "best way", I'd suggest you get rid of
the archaic "haul-all-params-ever-entered-with-me-around-hidden"
approach completely and use a decent session module that lets you
store intermediate results with a simple assignment, storing
everything in one go in the database and fetching it on session
initialization. This way, you only need one value (session id)
on the client side to keep track of everything.

An intuitive approach is the CGI::Session module, which already
comes with a mysql backend. Its use is quite similar to the
CGI module itself, so the learning curve isn't steep, and a
tutorial is also included. Even more concise in its usage is
Apache::Session, which lets you tie() your session storage to
a hash.

-Chris


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

Date: Thu, 06 Dec 2007 14:21:08 -0000
From: Justin C <justin.0711@purestblue.com>
Subject: Re: Nested sorting of a hash
Message-Id: <395e.47580554.b2a19@zem>

On 2007-12-06, Ben Morrow <ben@morrow.me.uk> wrote:
>
> Quoth justin.news@purestblue.com:
>> I have a hash containing stock codes (the keys) and the number of units
>> sold (the values). I can sort them easily to give the best selling items
>> at the top and those that sold the fewest at the bottom. There are many
>> items with the same number of units sold, what I'd like to do is sort
>> the keys within there relevant position in the in the list. 
><snip>
>> 
>> The sort I have for the hash so far is:
>> 
>>     foreach ( sort { $sales{$b} <=> $sales{$a} } keys %sales) {
>
>     foreach ( sort {
>         $sales{$b} <=> $sales{$a}
>             ||
>         $a cmp $b
>     } keys %sales ) {
>
>> 	print "$_;\t$sales{$_}\n";
>>     }
>
> The only time a sort expression returns false is when they compared
> equal, so you can combine them with ||.

Thank you for that. It's quite elegant really. Thanks also to Glenn for
(almost) the same answer... I say almost, is there any difference 
between || and 'or' in the above?

	Justin.

-- 
Justin C, by the sea.


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

Date: 6 Dec 2007 15:26:48 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Nested sorting of a hash
Message-Id: <slrnflg55p.qp6.glennj@smeagol.ncf.ca>

At 2007-12-06 09:21AM, "Justin C" wrote:
>  On 2007-12-06, Ben Morrow <ben@morrow.me.uk> wrote:
[...]
> >     foreach ( sort {
> >         $sales{$b} <=> $sales{$a}
> >             ||
> >         $a cmp $b
> >     } keys %sales ) {
> >
> >> 	print "$_;\t$sales{$_}\n";
> >>     }
> >
> > The only time a sort expression returns false is when they compared
> > equal, so you can combine them with ||.
>  
>  Thank you for that. It's quite elegant really. Thanks also to Glenn for
>  (almost) the same answer... I say almost, is there any difference 
>  between || and 'or' in the above?

Not in this case.  The only difference is precedence:  or is lower than ||
In other scenarios the difference is large.  See perldoc -q precedence and
perldoc perlop

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: Thu, 06 Dec 2007 16:36:37 GMT
From: "Jrgen Exner" <jurgenex@hotmail.com>
Subject: Re: Nested sorting of a hash
Message-Id: <pyV5j.7772$QS.7228@trndny03>

bugbear wrote:
> Justin C wrote:
>>
>> The sort I have for the hash so far is:
>>
>>     foreach ( sort { $sales{$b} <=> $sales{$a} } keys %sales) {
>> print "$_;\t$sales{$_}\n";
>>     }
>>
>> Thank you for any help you can give with this.
>
> You need to make your hash into an array of hashes, and sort that.

No, you don't.

> You cannot get the results you desire by sorting the keys;
> you must sort by considering the code/sold as a pair,
> using a primary/secondary comparison in the sort.

Which is trivial to do by augmenting the inline compare function with a 
secondary comparison in case the first one yields equal:

    $sales{$b} <=> $sales{$a} or $a cmp $b

This neat trick is mentioned in the docs, BTW:

     If you need to sort on several fields, the following paradigm is
     useful.
     @sorted = sort { field1($a) <=> field1($b) ||
                      field2($a) cmp field2($b) ||
                      field3($a) cmp field3($b)
                    }     @data;

jue 




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

Date: Thu, 06 Dec 2007 17:00:07 +0000
From: bugbear <bugbear@trim_papermule.co.uk_trim>
Subject: Re: Nested sorting of a hash
Message-Id: <13lgako5pu12d65@corp.supernews.com>

Jrgen Exner wrote:
> bugbear wrote:
>> Justin C wrote:
>>> The sort I have for the hash so far is:
>>>
>>>     foreach ( sort { $sales{$b} <=> $sales{$a} } keys %sales) {
>>> print "$_;\t$sales{$_}\n";
>>>     }
>>>
>>> Thank you for any help you can give with this.
>> You need to make your hash into an array of hashes, and sort that.
> 
> No, you don't.

You're right, of courtse; I was having a bad morning :-(

   BugBear


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

Date: 6 Dec 2007 17:48:39 GMT
From: Glenn Jackman <glennj@ncf.ca>
Subject: Re: Nested sorting of a hash
Message-Id: <slrnflgdfo.qp6.glennj@smeagol.ncf.ca>

At 2007-12-06 11:36AM, "Jrgen Exner" wrote:
>       If you need to sort on several fields, the following paradigm is
>       useful.
>       @sorted = sort { field1($a) <=> field1($b) ||
>                        field2($a) cmp field2($b) ||
>                        field3($a) cmp field3($b)
>                      }     @data;

If the field lookup is expensive, you'd want the orcish maneuver or a
schwartzian transform:
    http://www.perlmonks.org/?node_id=128722

-- 
Glenn Jackman
"You can only be young once. But you can always be immature." -- Dave Barry


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

Date: Thu, 06 Dec 2007 17:59:36 GMT
From: "Jrgen Exner" <jurgenex@hotmail.com>
Subject: Re: Nested sorting of a hash
Message-Id: <cMW5j.11024$VJ.10333@trndny05>

Glenn Jackman wrote:
> At 2007-12-06 11:36AM, "Jrgen Exner" wrote:
>>       If you need to sort on several fields, the following paradigm
>>       is useful.
>>       @sorted = sort { field1($a) <=> field1($b) ||
>>                        field2($a) cmp field2($b) ||
>>                        field3($a) cmp field3($b)
>>                      }     @data;
>
> If the field lookup is expensive,

Which obviously is not the case for the OP.

> you'd want the orcish maneuver or a
> schwartzian transform:
>    http://www.perlmonks.org/?node_id=128722

Which is actually mentioned in the lines above the except that I quoted with 
an additional pointer just following my excerpt (see 'perldoc -q sort'):

     This can be conveniently combined with precalculation of keys as
     given above.

I don't think there is any need to emphasize the point in the FAQ even 
further.

jue




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

Date: Thu, 06 Dec 2007 19:51:03 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Nested sorting of a hash
Message-Id: <x7y7c7ob4p.fsf@mail.sysarch.com>

>>>>> "GJ" == Glenn Jackman <glennj@ncf.ca> writes:

  GJ> At 2007-12-06 11:36AM, "Jrgen Exner" wrote:
  >> If you need to sort on several fields, the following paradigm is
  >> useful.
  >> @sorted = sort { field1($a) <=> field1($b) ||
  >> field2($a) cmp field2($b) ||
  >> field3($a) cmp field3($b)
  >> }     @data;

  GJ> If the field lookup is expensive, you'd want the orcish maneuver or a
  GJ> schwartzian transform:
  GJ>     http://www.perlmonks.org/?node_id=128722

the orcish is actually fairly slow. but you can compare all the sort
speedup techniques with Sort::Maker and even see the generated code. the
benchmark script in the tarball shows that the GRT is the fastest for
most multilevel sorting.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 6 Dec 2007 18:06:21 GMT
From: Dominique Dumont <dominique.dumont@hp.com>
Subject: New version of Config::Model (v0.616): INI file support
Message-Id: <Jsn6A5.F85@zorch.sf-bay.org>


Hello

I've uploaded version 0.616 of Config::Model perl module.

Config::Model enables a project developer to provide a configuration
editor (with help and validatio) to his users. For this, the developer
must describe the structure and constraint of his project's
configuration (i.e. the configuration model).

This release brings a built-in support to read and write configuration
data from:
- "INI" file (require Config::Tiny)
- perl file (using a perl data structure.) 

I could use some help to provide a graphic interface to Config::Model
and a web interface. Send me a mail if you're interested in
contributing to this project.

For details on Config::Model see:

http://freshmeat.net/projects/config_model/
http://config-model.wiki.sourceforge.net/
http://search.cpan.org/dist/Config-Model/

Cheers

-- 
Dominique Dumont 
"Delivering successful solutions requires giving people what they
need, not what they want." Kurt Bittner




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

Date: Thu, 6 Dec 2007 12:31:24 -0800 (PST)
From: joeyfoley <joey.foley@gmail.com>
Subject: sprintf or format
Message-Id: <7ee2d8d9-0821-450c-9bdb-1b23768ffa92@r60g2000hsc.googlegroups.com>

Hi All,

I have a file that I am reading in that I need to reprint and format
the output.

There are 4 parts that need to be printed on a line.

Name 1-14
Type 16-22
Start 24-28 (left justified)
Width 30-32 (left justified)

However, if the name is greater than 14 characters, then the rest of
the code is moved right accordingly.

The algorithm is basically:

If length(Name) <=14 then:
  print @1   Name
  print @16 Type
  print @24 Start (left justified)
  print @30 Width (left justified)
else
  print @1  Name
  print@(length(name)+1) Type
  print@(length(name)+10) Start (left justified)
  print@(length(name)+15) Width (left justified)

How do I print with this algorithm?

Thanks.





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

Date: Thu, 06 Dec 2007 11:16:13 -0600
From: gilgames <glgas@aim.com>
Subject: Tk Optionmenu foreground colors
Message-Id: <y7W5j.30678$Pv2.30105@newssvr23.news.prodigy.net>

May be somebody could help me out.

I use Tk the version from 2004. I have to make a change which allows 
black background (same people see it better). I was successful with all 
the widgets, except Optionmenu. I can change the -background option, but 
the -foreground (text color) is always black or some kind of gray. 
-activeForeground is rejected when the program is loaded. I see the 
highlighted foreground (when the cursor is over the widget or selection) 
but do not see options in not highlighted state.

here is the command I use

 
$parwidget[$i]->Optionmenu(-options=>\@optarray,-textvariable=>$myvariable,
  -takefocus=>1,-font=>$myfont,
  -background=>"black",-foreground=>"white",
  -command=>sub{"myfunc()")});

Everything works fine since years except the -foreground color

Thanks in advance



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

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 V11 Issue 1094
***************************************


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