Perl

Moderators: Jonathan
Number of threads: 1259
Number of posts: 3644

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Problem in displaying the contents of the Array Posted by snitch on 19 Feb 2004 at 10:39 PM
Hi there,

This code snippet is not working.

#!C:\Perl\bin\perl.exe

print "Content-type: text/html\r\n\r\n";

print "<Head>";
print "<Title>";
print "Temp";
print "</Title>";
print "<body>";

@temp = {1,2,3};
print "$temp[0]";

the output is

HASH(0x17ff06c)

donno y ??
any help ???

thanks in advance

curcio,
snitch
Report
Re: Problem in displaying the contents of the Array Posted by Xfactor on 20 Feb 2004 at 12:12 AM
: Hi there,
:
: This code snippet is not working.
:
: #!C:\Perl\bin\perl.exe
:
: print "Content-type: text/html\r\n\r\n";
:
: print "<Head>";
: print "<Title>";
: print "Temp";
: print "</Title>";
: print "<body>";
:
: @temp = {1,2,3};
: print "$temp[0]";
:
: the output is
:
: HASH(0x17ff06c)
:
: donno y ??
: any help ???
:
: thanks in advance
:
: curcio,
: snitch

You declared the @temp variable wrong. To initialize an array, you do it like this:
@temp = (1..3); # initializes 1 through 3

or you can even do something like this:
@nums = (0..8,11,15,22..33);

Hope this helps.

X
Report
Re: Problem in displaying the contents of the Array Posted by snitch on 20 Feb 2004 at 12:59 AM
Hi,
Thanx a lot.
This is working.
Now i am facing another problem.

$dir='D:\\';
opendir(DIR, $dir)
@dots = readdir(DIR);
print $dots[0];

nothing is displaying on the screen.
what might be the problem ???

Here i want the contents of the directory in the array dots.

thanks,
snitch

: : Hi there,
: :
: : This code snippet is not working.
: :
: : #!C:\Perl\bin\perl.exe
: :
: : print "Content-type: text/html\r\n\r\n";
: :
: : print "<Head>";
: : print "<Title>";
: : print "Temp";
: : print "</Title>";
: : print "<body>";
: :
: : @temp = {1,2,3};
: : print "$temp[0]";
: :
: : the output is
: :
: : HASH(0x17ff06c)
: :
: : donno y ??
: : any help ???
: :
: : thanks in advance
: :
: : curcio,
: : snitch
:
: You declared the @temp variable wrong. To initialize an array, you do it like this:
: @temp = (1..3); # initializes 1 through 3
:
: or you can even do something like this:
: @nums = (0..8,11,15,22..33);
:
: Hope this helps.
:
: X
:

Report
Re: Problem in displaying the contents of the Array Posted by Xfactor on 20 Feb 2004 at 1:27 AM
: Hi,
: Thanx a lot.
: This is working.
: Now i am facing another problem.
:
: $dir='D:\\';
: opendir(DIR, $dir)
: @dots = readdir(DIR);
: print $dots[0];
:
: nothing is displaying on the screen.
: what might be the problem ???
:
: Here i want the contents of the directory in the array dots.
:
: thanks,
: snitch

That looks right to me. The only logical thing is $dots[0] doesn't have anything in it to print. I don't know why that would be.
Try printing the whole array like this:
print "@dots\n";
or
foreach (@dots) {
print "$_\n";
}

This will show if anything is in the dots variable.
Report
Re: Problem in displaying the contents of the Array Posted by Weirdofreak on 21 Feb 2004 at 1:05 PM
You need a semi-colon at the end of the opendir line. It tries to interpret
opendir(DIR, $dir) @dots = readdir(DIR)
as a single line, can't figure out what the hell is going on, and barfs up an error, which gets sent to STDERR (a log file) instead of STDOUT (the browser) so you don't see it on the screen.

You should probably also check the opendir worked -
opendir(DIR, $dir) or @dots = ("Filed to open directory $dir");
because otherwise if the directory doesn't open, it'll send the error to the logs, not the browser.
Report
Re: Problem in displaying the contents of the Array Posted by Jonathan on 21 Feb 2004 at 1:54 PM
: You need a semi-colon at the end of the opendir line. It tries to interpret
: opendir(DIR, $dir) @dots = readdir(DIR)
: as a single line, can't figure out what the hell is going on, and barfs up an error, which gets sent to STDERR (a log file) instead of STDOUT (the browser) so you don't see it on the screen.
:
: You should probably also check the opendir worked -
: opendir(DIR, $dir) or @dots = ("Filed to open directory $dir");
: because otherwise if the directory doesn't open, it'll send the error to the logs, not the browser.
:
Good catch! I sat and looked at that code for a couple of minutes and missed that one. Oops.

Jonathan

###
for(74,117,115,116){$::a.=chr};(($_.='qwertyui')&&
(tr/yuiqwert/her anot/))for($::b);for($::c){$_.=$^X;
/(p.{2}l)/;$_=$1}$::b=~/(..)$/;print("$::a$::b $::c hack$1.");

Report
Re: Problem in displaying the contents of the Array Posted by Xfactor on 21 Feb 2004 at 7:48 PM
: : You need a semi-colon at the end of the opendir line. It tries to interpret
: : opendir(DIR, $dir) @dots = readdir(DIR)
: : as a single line, can't figure out what the hell is going on, and barfs up an error, which gets sent to STDERR (a log file) instead of STDOUT (the browser) so you don't see it on the screen.
: :
: : You should probably also check the opendir worked -
: : opendir(DIR, $dir) or @dots = ("Filed to open directory $dir");
: : because otherwise if the directory doesn't open, it'll send the error to the logs, not the browser.
: :
: Good catch! I sat and looked at that code for a couple of minutes and missed that one. Oops.
:
: Jonathan

I missed that one too.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.