Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Problem in displaying the contents of the Array

snitchsnitch Posts: 13Member
Hi there,

This code snippet is not working.

#!C:Perlinperl.exe

print "Content-type: text/html

";

print "";
print "";
print "Temp";
print "";
print "";

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

the output is

HASH(0x17ff06c)

donno y ??
any help ???

thanks in advance

curcio,
snitch

Comments

  • XfactorXfactor Posts: 343Member
    : Hi there,
    :
    : This code snippet is not working.
    :
    : #!C:Perlinperl.exe
    :
    : print "Content-type: text/html

    ";
    :
    : print "";
    : print "";
    : print "Temp";
    : print "";
    : print "";
    :
    : @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
  • snitchsnitch Posts: 13Member
    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:Perlinperl.exe
    : :
    : : print "Content-type: text/html

    ";
    : :
    : : print "";
    : : print "";
    : : print "Temp";
    : : print "";
    : : print "";
    : :
    : : @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
    :

  • XfactorXfactor Posts: 343Member
    : 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
    ";
    or
    foreach (@dots) {
    print "$_
    ";
    }

    This will show if anything is in the dots variable.
  • WeirdofreakWeirdofreak Posts: 439Member
    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.
  • JonathanJonathan Posts: 2,914Member
    : 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.");

  • XfactorXfactor Posts: 343Member
    : : 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.
Sign In or Register to comment.