Howdy, Stranger!

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

Categories

although there's a print command perl doesn't print

FirestormFirestorm Member Posts: 162
here is a snippet of my code
[code]
open (READ, ";
@read[$i] = $read;
}
for ($j = $i; $j = 0; $j = $j - 1)
{
print @read[$j];
}
close (READ);
[/code]
before that there is a
print "Content-type: text/html

";
and some html to print
after that also some html to print

my problem is that all html is printed but not the text from g.dat!!
Firestorm
fgretz@gmx.de
;-)

Comments

  • SouldrinkerSouldrinker Member Posts: 143
    First of all try this code...

    [code]
    open (READ, ")
    {
    push @read, $_;
    }

    foreach (@read)
    {
    print $_;
    }

    close (READ);
    [/code]

    This should work better, because push often works better with arrays, if it still does not work the way you want it to, try some "print $#read;" to see how much elements the array @read has got.

    Some suggestion on your problem: you used $read and @read to save different values, could be that perl does not like this, depending on the version of the interpretor of course.

    Please post if it works or not ;)

    greetings

    souldrinker
  • oggioggi Member Posts: 4
    : here is a snippet of my code
    : [code]
    : open (READ, ";
    : @read[$i] = $read;
    : }
    : for ($j = $i; $j = 0; $j = $j - 1)
    : {
    : print @read[$j];
    : }
    : close (READ);
    : [/code]
    : before that there is a
    : print "Content-type: text/html

    ";
    : and some html to print
    : after that also some html to print
    :
    : my problem is that all html is printed but not the text from g.dat!!
    : Firestorm
    : fgretz@gmx.de
    : ;-)
    :

    In the condition part of the for statement, you wrote $j = 0; .
    This assigns $j to 0 . So, the expression has value 0.
    This cause the immediate termination of the loop.
    (does not even begin the loop.)

    Try the following codes.

    open (READ, ";
    @read[$i] = $read;
    }
    for ($j = $i; $j >= 0; $j = $j - 1)
    {
    print @read[$j];
    }
    close (READ);

    This may fixes your problem. But, you may want to use chomp() also.


  • FirestormFirestorm Member Posts: 162
    [b][red]This message was edited by the Firestorm at 2002-6-30 12:10:25[/red][/b][hr]
    I experimented and found a confirmation of what I was thinking:
    evrything is written right except of the for{} which is skipped by the script because the condition must be wrong!!
    what I have at the moment is
    [code]
    open (READ, ";
    @filecontent[$i] = $read;
    print $i;
    }
    for ($j = $i; $j = 0; $j = $j - 1)
    {
    print @filecontent[$j];
    }
    print $#filecontent;
    close (READ);
    [/code]
    it prints that I have 17 lines from 0 to 16
    and that @filecontent(which I renamed from @read) has got 16 positions (starting with 0).
    which is all right.

    Well I'll try now to replace my for condition with an other.
    Firestorm
    fgretz@gmx.de
    ;-)



  • bgibbybgibby Member Posts: 251
    : here is a snippet of my code
    : [code]
    : open (READ, ";
    : @read[$i] = $read;
    : }
    : for ($j = $i; $j = 0; $j = $j - 1)
    : {
    : print @read[$j];
    : }
    : close (READ);
    : [/code]
    : before that there is a
    : print "Content-type: text/html

    ";
    : and some html to print
    : after that also some html to print
    :
    : my problem is that all html is printed but not the text from g.dat!!
    : Firestorm
    : fgretz@gmx.de
    : ;-)
    :

    Hi there,

    You're saying in your FOR statment, $j = something, if $j assign 0 (returns 0), take 1 from $j.

    I think you should be saying,

    [code]
    for ($j = $i; $j != 0; $j--)
    [/code]

    You code prints nothing because $j = 0 returns 0. The FOR loop only get's executed IF the conditional expression returns 1.

    You could re-write your code like this to get the same effect...

    [code]

    open (READ, "g.dat") || print "g.dat not found!"; # < is implict

    while () {
    push(@READ, $_);
    print;
    }

    close (READ);

    [/code]

    Hope this helps!
    Bradley q:)
  • FirestormFirestorm Member Posts: 162
    Thanks to everybody who tryed to help!
    What I just did is change the condition to >=0 what I think is illogical but anyway it works!
    : [code]
    : open (READ, ";
    : @read[$i] = $read;
    : }
    : for ($j = $i; $j [red]>[/red]= 0; $j = $j - 1)
    : {
    : print @read[$j];
    : }
    : close (READ);
    : [/code]

    Firestorm
    fgretz@gmx.de
    ;-)

  • Chris BrownChris Brown USAMember Posts: 4,496 ✭✭

    ______ { http://forcoder.org } free ebooks and video tutorials about / Java, Python, PHP, C#, Scratch, R, Perl, Delphi, Assembly, Objective-C, Ruby, PL/SQL, Go, JavaScript, Visual Basic .NET, Visual Basic, MATLAB, C, Swift, C++ Scheme, Clojure, Lua, COBOL, SAS, Bash, Prolog, FoxPro, Ada, D, Alice, Transact-SQL, Hack, ABAP, Rust, Awk, Dart, Crystal, Lisp, Apex, Fortran, Julia, Logo, Erlang, VBScript, Scala, ML, F#, Kotlin, LabVIEW / ______________

Sign In or Register to comment.