For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > July 2006 > Ububg aus dem Kamelbuch









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Ububg aus dem Kamelbuch
javier@callwayonline.de

2006-07-27, 3:57 am

Hallo,

ich versuche folgedes aus dem Programmieren mit perl:

while ( <> ) {

next unless s/^(.*?):\s*//;
$HoL{$1} =3D [ split ];

}

die Hash Datei sieht folgenden aus

1: 1 2 3 4 5 6
2: 34 5 7 8 9
usw.

wenn ich der Skript auf eine Win Xp Pro mit perl activestate 5.8

perl -w HoL.pl Hash.txt

aufrufe

Bekomme ich folgende Fehlermeldung:

Name "main::HoL" used only once: possible typo at HoL.pl line 12

genau das gleiche wenn das skript so umgeschrieben wird:

while ($line =3D <> ){
($who, $rest) =3D split /:\s*/, $line, 2;
@field =3D split ' ', $rest;
$HoL{$who} =3D [ @field ];

}

was mache ich falsch?

Gr=FC=DFe.

Xaver

usenet@DavidFilmer.com

2006-07-27, 3:57 am

javier@callwayonline.de wrote:
> Hallo,
> ich versuche folgedes aus dem Programmieren mit perl:
>
> while ( <> ) {
>
> next unless s/^(.*?):\s*//;
> $HoL{$1} = [ split ];
> }
>
> Bekomme ich folgende Fehlermeldung:
>
> Name "main::HoL" used only once: possible typo at HoL.pl line 12


There is something that you are not telling us. The first code you
posted should produce identical results as the second code. But you
only posted a code fragment... either your posting doesn't match your
code, or something else is happening that you haven't shown us.

A good debugging technique is to write a short but complete test
program that can reproduce the error. Then post that here.

If I do this with the code you provided, I would write something like
this:

#!/usr/bin/perl
use strict; use warnings;
use Data::Dumper;

my %HoL;
while ( <DATA> ) {
next unless s/^(.*?):\s*//;
$HoL{$1} = [ split ];
}

print Dumper \%HoL;

__DATA__
1: 1 2 3 4 5 6
2: 34 5 7 8 9

Which , of course, works exactly as you would expect (and I will bet
you a pils that it does exactly the same thing on your system). So
what is missing from this sample program that causes the error within
your script?

--
David Filmer (http://DavidFilmer.com)

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com