[31937] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3200 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sun Nov 7 06:09:58 2010

Date: Sun, 7 Nov 2010 03:09:41 -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           Sun, 7 Nov 2010     Volume: 11 Number: 3200

Today's topics:
        create a plain text table <dontmewithme@got.it>
    Re: create a plain text table <derykus@gmail.com>
    Re: create a plain text table <dontmewithme@got.it>
    Re: create a plain text table <rvtol+usenet@xs4all.nl>
        Trouble passing arguments to subroutine <laredotornado@zipmail.com>
    Re: Trouble passing arguments to subroutine <sherm.pendley@gmail.com>
    Re: Trouble passing arguments to subroutine <glex_no-spam@qwest-spam-no.invalid>
    Re: Trouble passing arguments to subroutine <jurgenex@hotmail.com>
        What does it mean: "Trailing \ in regex m/\\\/ at ... <rxjwg98@gmail.com>
    Re: What does it mean: "Trailing \ in regex m/\\\/ at . <tadmc@seesig.invalid>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Fri, 5 Nov 2010 22:31:29 +0100
From: "Larry" <dontmewithme@got.it>
Subject: create a plain text table
Message-Id: <4cd477b5$0$40010$4fafbaef@reader3.news.tin.it>

I am really at a loss with the following. I have a big multidimendionas hash 
made up like this:

$OI->{"dd/mm/yyyy"}->{"name"}->{"expire date"}->{"strike"}->{"type"} = 
num_val

where TYPE can ben "Call" or "Put" and STRIKE is a numeric value.

I fill in that hash by parsing an xml file like this:

 ...
<OI date="04/10/2010" name="AAPL" exp_date="DEC2010" strike="320" call="30" 
put="50" />
<OI date="04/10/2010" name="AAPL" exp_date="DEC2010" strike="320" call="100" 
put="172" />
 ...

I need to create a table (plain text) out of that hash, something as follows

name: ( #workbook
   expire date: ( #worksheet 1
      strike  type  dd/mm/yyyy  dd/mm/yyyy  dd/mm/yyyy  ..etc..

      15      Call  num_val     num_val     num_val
      15      Put   num_val     num_val     num_val

      16      Call  num_val     num_val     num_val
      16      Put   num_val     num_val     num_val

      ..etc..

   )

   expire date: ( #worksheet2
      strike  type  dd/mm/yyyy  dd/mm/yyyy  dd/mm/yyyy  ..etc..

      15      Call  num_val     num_val     num_val
      15      Put   num_val     num_val     num_val

      16      Call  num_val     num_val     num_val
      16      Put   num_val     num_val     num_val

      ..etc..

   )
)

basicaly the STRIKE field is supposed to be sorted by ascending
and the DD/MM/YYYY is supposed to be sorted by older->newer

Any help will be appreciated on how to go about making that possible in 
Perl!

thanks



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

Date: Fri, 5 Nov 2010 17:45:34 -0700 (PDT)
From: "C.DeRykus" <derykus@gmail.com>
Subject: Re: create a plain text table
Message-Id: <2a4d58d6-389b-4681-8f92-f347b9b4128d@x4g2000pre.googlegroups.com>

On Nov 5, 2:31=A0pm, "Larry" <dontmewit...@got.it> wrote:
> I am really at a loss with the following. I have a big multidimendionas h=
ash
> made up like this:
>
> $OI->{"dd/mm/yyyy"}->{"name"}->{"expire date"}->{"strike"}->{"type"} =3D
> num_val
>
> where TYPE can ben "Call" or "Put" and STRIKE is a numeric value.
>
> I fill in that hash by parsing an xml file like this:
>
> ...
> <OI date=3D"04/10/2010" name=3D"AAPL" exp_date=3D"DEC2010" strike=3D"320"=
 call=3D"30"
> put=3D"50" />
> <OI date=3D"04/10/2010" name=3D"AAPL" exp_date=3D"DEC2010" strike=3D"320"=
 call=3D"100"
> put=3D"172" />
> ...
>
> I need to create a table (plain text) out of that hash, something as foll=
ows
>
> name: ( #workbook
> =A0 =A0expire date: ( #worksheet 1
> =A0 =A0 =A0 strike =A0type =A0dd/mm/yyyy =A0dd/mm/yyyy =A0dd/mm/yyyy =A0.=
 .etc..
>
> =A0 =A0 =A0 15 =A0 =A0 =A0Call =A0num_val =A0 =A0 num_val =A0 =A0 num_val
> =A0 =A0 =A0 15 =A0 =A0 =A0Put =A0 num_val =A0 =A0 num_val =A0 =A0 num_val
>
> =A0 =A0 =A0 16 =A0 =A0 =A0Call =A0num_val =A0 =A0 num_val =A0 =A0 num_val
> =A0 =A0 =A0 16 =A0 =A0 =A0Put =A0 num_val =A0 =A0 num_val =A0 =A0 num_val
>
> =A0 =A0 =A0 ..etc..
>
> =A0 =A0)
>
> =A0 =A0expire date: ( #worksheet2
> =A0 =A0 =A0 strike =A0type =A0dd/mm/yyyy =A0dd/mm/yyyy =A0dd/mm/yyyy =A0.=
 .etc..
>
> =A0 =A0 =A0 15 =A0 =A0 =A0Call =A0num_val =A0 =A0 num_val =A0 =A0 num_val
> =A0 =A0 =A0 15 =A0 =A0 =A0Put =A0 num_val =A0 =A0 num_val =A0 =A0 num_val
>
> =A0 =A0 =A0 16 =A0 =A0 =A0Call =A0num_val =A0 =A0 num_val =A0 =A0 num_val
> =A0 =A0 =A0 16 =A0 =A0 =A0Put =A0 num_val =A0 =A0 num_val =A0 =A0 num_val
>
> =A0 =A0 =A0 ..etc..
>
> =A0 =A0)
> )
>
> basicaly the STRIKE field is supposed to be sorted by ascending
> and the DD/MM/YYYY is supposed to be sorted by older->newer
>
> Any help will be appreciated on how to go about making that possible in
> Perl!
>

Are you looking for help in walking through
the data structure, sorting, or formatting
the output table...?

Have you researched Perl's online docs:
   perldoc perldsc
   perldoc -f sort
   perldoc -f printf
   perldoc perlform


CPAN:  Text::Table is another possibility for
       output formatting.

--
Charles DeRykus


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

Date: Sat, 6 Nov 2010 01:58:37 +0100
From: "Larry" <dontmewithme@got.it>
Subject: Re: create a plain text table
Message-Id: <4cd4a842$0$26699$4fafbaef@reader1.news.tin.it>


"Larry" <dontmewithme@got.it> ha scritto nel messaggio 
news:4cd477b5$0$40010$4fafbaef@reader3.news.tin.it...
>I am really at a loss with the following. I have a big multidimendionas 
>hash made up like this:
>
> $OI->{"dd/mm/yyyy"}->{"name"}->{"expire date"}->{"strike"}->{"type"} = 
> num_val
>
> where TYPE can ben "Call" or "Put" and STRIKE is a numeric value.
>
> I fill in that hash by parsing an xml file like this:
>
> ...
> <OI date="04/10/2010" name="AAPL" exp_date="DEC2010" strike="320" 
> call="30" put="50" />
> <OI date="04/10/2010" name="AAPL" exp_date="DEC2010" strike="320" 
> call="100" put="172" />
> ...
>
> I need to create a table (plain text) out of that hash, something as 
> follows
>
> name: ( #workbook
>   expire date: ( #worksheet 1
>      strike  type  dd/mm/yyyy  dd/mm/yyyy  dd/mm/yyyy  ..etc..
>
>      15      Call  num_val     num_val     num_val
>      15      Put   num_val     num_val     num_val
>
>      16      Call  num_val     num_val     num_val
>      16      Put   num_val     num_val     num_val
>
>      ..etc..
>
>   )
>
>   expire date: ( #worksheet2
>      strike  type  dd/mm/yyyy  dd/mm/yyyy  dd/mm/yyyy  ..etc..
>
>      15      Call  num_val     num_val     num_val
>      15      Put   num_val     num_val     num_val
>
>      16      Call  num_val     num_val     num_val
>      16      Put   num_val     num_val     num_val
>
>      ..etc..
>
>   )
> )
>
> basicaly the STRIKE field is supposed to be sorted by ascending
> and the DD/MM/YYYY is supposed to be sorted by older->newer
>
> Any help will be appreciated on how to go about making that possible in 
> Perl!
>
> thanks
>

I think I'll stick with DBI and SQLite... 



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

Date: Sat, 06 Nov 2010 12:21:00 +0100
From: "Dr.Ruud" <rvtol+usenet@xs4all.nl>
Subject: Re: create a plain text table
Message-Id: <4cd53a1c$0$81483$e4fe514c@news.xs4all.nl>

On 2010-11-05 22:31, Larry wrote:

> $OI->{"dd/mm/yyyy"} ...

Just a weekend thought:

When I see something like that, I stop reading. I really dislike it when 
the display level creeps into the code like that.

-- 
Ruud


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

Date: Fri, 5 Nov 2010 13:41:45 -0700 (PDT)
From: laredotornado <laredotornado@zipmail.com>
Subject: Trouble passing arguments to subroutine
Message-Id: <68b7fff0-7408-46d7-b5ff-cf28d55922f0@n32g2000prc.googlegroups.com>

Hi,

I want to create a function that takes a hash (by reference) and a
scalar as arguments.  I'm trying ...

sub add_to_block_hash
{
        my (%blocks, $curBlock) = @_;
        print "curblock: $curBlock\n";    # line 33
 ...


add_to_block_hash(\%blocks, $curBlock);


but I'm getting the error, "Use of uninitialized value in
concatenation (.) or string at test.pl line 33" in which line 33 is
marked above.  How do I correct this?  THanks, - Dave


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

Date: Fri, 05 Nov 2010 16:55:37 -0400
From: Sherm Pendley <sherm.pendley@gmail.com>
Subject: Re: Trouble passing arguments to subroutine
Message-Id: <m2r5ezze0m.fsf@sherm.shermpendley.com>

laredotornado <laredotornado@zipmail.com> writes:

> Hi,
>
> I want to create a function that takes a hash (by reference) and a
> scalar as arguments.  I'm trying ...
>
> sub add_to_block_hash
> {
>         my (%blocks, $curBlock) = @_;

You're passing a hashref, so you need to treat it as such within the
subroutine as well:

        my ($blocks, $curBlock) = @_;

>         print "curblock: $curBlock\n";    # line 33
> ...
>
> add_to_block_hash(\%blocks, $curBlock);
>
> but I'm getting the error, "Use of uninitialized value in
> concatenation (.) or string at test.pl line 33" in which line 33 is
> marked above.  How do I correct this?  THanks, - Dave

For more about references, see:

    perldoc perlreftut
    perldoc perlref

sherm--

-- 
Sherm Pendley
                                   <http://camelbones.sourceforge.net>
Cocoa Developer


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

Date: Fri, 05 Nov 2010 15:57:52 -0500
From: "J. Gleixner" <glex_no-spam@qwest-spam-no.invalid>
Subject: Re: Trouble passing arguments to subroutine
Message-Id: <4cd46fd0$0$87070$815e3792@news.qwest.net>

laredotornado wrote:
> Hi,
> 
> I want to create a function that takes a hash (by reference) and a
> scalar as arguments.  I'm trying ...
> 
> sub add_to_block_hash
> {
>         my (%blocks, $curBlock) = @_;
               ^^^^^^^ hash, not a reference
>         print "curblock: $curBlock\n";    # line 33
> ...
> 
> 
> add_to_block_hash(\%blocks, $curBlock);
                     ^^^^^^^ reference to a hash
> 
> 
> but I'm getting the error, "Use of uninitialized value in
> concatenation (.) or string at test.pl line 33" in which line 33 is
> marked above.  How do I correct this?  THanks, - Dave

sub add_to_block_hash {
	my ($blocks, $curBlock) = @_;

Then, dereference $blocks.

e.g.
	for my $k ( keys %$blocks ) { ...}


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

Date: Fri, 05 Nov 2010 18:20:38 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: Trouble passing arguments to subroutine
Message-Id: <p4b9d6djjher9100e87lhiivrt4oa7060l@4ax.com>

laredotornado <laredotornado@zipmail.com> wrote:
>I want to create a function that takes a hash (by reference) and a
>scalar as arguments.  I'm trying ...
>
>sub add_to_block_hash
>{
>        my (%blocks, $curBlock) = @_;
             ^^^^^^^
This hash will suck up all the arguments provided, leaving nothing for
$curBlock. And because you are passing an even number of arguments you
are not even getting a warning that you are trying to create a hash with
an odd number of elements.
If you are passing a hash ref, then you need to treat it as hash ref:

        my ($blockRef, $curBlock) = @_;

jue


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

Date: Fri, 5 Nov 2010 17:47:05 -0700 (PDT)
From: fl <rxjwg98@gmail.com>
Subject: What does it mean: "Trailing \ in regex m/\\\/ at ...
Message-Id: <a501aa16-f8ac-45f0-8f81-9aa59363ff6b@s4g2000yql.googlegroups.com>

Hi,
I am learning an example, see below part. I find that there is a
special message from the running of the example when I input three
\'s (\\\). It says  was not found when I input two, four or other
number \.

My question is: 1. Why it only has this output for three \. 2. What is
the meaning: "Trailing \ in regex m/\\\/ at matchtest.plx line 13,
<STDIN> line 1. Thanks.





 .......
#!/usr/bin/perl
# matchtest.plx
use warnings;
use strict;

$_ = q("I wonder what the Entish is for 'yes' and 'no'," he thought.);
# Tolkien, Lord of the Rings

print "Enter some text to find: ";
my $pattern = <STDIN>;
chomp($pattern);

if (/$pattern/) {
	print "The text matches the pattern '$pattern'.\n";
} else {
	print "'$pattern' was not found.\n";
}


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

Date: Fri, 05 Nov 2010 23:10:01 -0500
From: Tad McClellan <tadmc@seesig.invalid>
Subject: Re: What does it mean: "Trailing \ in regex m/\\\/ at ...
Message-Id: <slrnid9llq.ue4.tadmc@tadbox.sbcglobal.net>

fl <rxjwg98@gmail.com> wrote:
> Hi,
> I am learning an example, see below part. I find that there is a
> special message 


Did you look up the message in

    perldoc perldiag

??

Or, put

    use diagnostics;

at the top of your program and run it again, and perl will look up
the message in perldiag.pod for you.


> from the running of the example when I input three
> \'s (\\\). It says  was not found when I input two, four or other
> number \.
>
> My question is: 1. Why it only has this output for three \. 


It doesn't only make the message for three backslashes, it makes
the message for any odd number of backslashes. Try it with
one and with five backslashes.


> 2. What is
> the meaning: "Trailing \ in regex m/\\\/ at matchtest.plx line 13,
><STDIN> line 1. Thanks.


It means you have a (regex) syntax error.

When you say

    m/\\/

the regex engine sees one backslash. When you say

    m/\\\\/

the regex engine sees two backslashes. When you say

    m/\\\/

the regex engine sees an invalid regex.


The match operator (m//) is "double quotish", that is, it acts
like a double quoted string.

    print "\\", "\n";

outputs one backslash.

    print "\\\\", "\n";

outputs two backslashes.

    print "\\\", "\n";

outputs a different syntax error message.


-- 
Tad McClellan
email: perl -le "print scalar reverse qq/moc.liamg\100cm.j.dat/"
The above message is a Usenet post.
I don't recall having given anyone permission to use it on a Web site.


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

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:

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

Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests. 

#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 3200
***************************************


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