Question from perl newbie

Discussion in 'Perl' started by Victor, Dec 15, 2006.

  1. Victor

    Victor Guest

    I downloaded and installed Perl, seemingly in a successful manner to a
    Windows XP computer. then I wrote the following code to a file,
    Example_4_1.pl:

    #! ..\bin\perl -w
    $DNA = 'abc' ;
    print $DNA ;
    exit ;


    Then, I run:

    > perl Example_4_1.pl


    The program seems to run without complaints, yet I don't see the output of
    the print statement. What do I need to do to be able to see the output?

    Thanks,
    Victor
    Victor, Dec 15, 2006
    #1
    1. Advertising

  2. Victor

    Skeleton Man Guest

    >The program seems to run without complaints, yet I don't see the output of
    >the print statement. What do I need to do to be able to see the output?


    Are you running it from a dos window or start -> run -> "perl
    Example_4_1.pl" ? If you try the latter the window will close immediately
    after the script finishes, hence you won't see the output.. You will want
    to fire a dos prompt and from there you can run "perl Example_4_1.pl"..

    Regards,
    Chris
    Skeleton Man, Dec 15, 2006
    #2
    1. Advertising

  3. [X-Post and follow-up to CLPM because CLP has been a zombie for many years,
    please see the FAQ]

    Victor wrote:
    > I downloaded and installed Perl, seemingly in a successful manner to a
    > Windows XP computer. then I wrote the following code to a file,
    > Example_4_1.pl:
    >
    > #! ..\bin\perl -w


    Windows doesn't care about the shebang line. You can just as well leave it
    out.
    The command line option -w is outdated. It is better to use
    use warnings;
    instead.

    > $DNA = 'abc' ;
    > print $DNA ;
    > exit ;


    If exit is the last statement and you are not returning any special value
    then you may just as well omit it.

    > Then, I run:
    >
    >> perl Example_4_1.pl


    Normally your Perl installation should have associated the .pl extension
    with the Perl interpreter, such that you can run any Perl program by just
    typing its name without calling the interpreter directly.

    Example_4_1.pl

    > The program seems to run without complaints, yet I don't see the
    > output of the print statement. What do I need to do to be able to
    > see the output?


    That is weird. There is nothing wrong with your Perl code.
    Maybe someone in CLPM knowns.

    jue
    Jürgen Exner, Dec 18, 2006
    #3
  4. Victor

    Roy Jaffray Guest

    am a newbie as well .. with exactly the same problem.

    I have a file called "helloworld.pl". When it wouldnt put out any output
    using <stdin> I decided to try to create and open a file and write to that.

    ____helloworld.pl________________________________
    open(geo,">perltest.txt") or die ("Cannot Open perltest.txt");


    for ($loop_index =1; $loop_index <=5; $loop_index++)
    {
    Print geo "hello world!\n"
    }
    Print "there!\n\n\n"
    close (geo);
    print "Press <enter> to continue" ;
    <stdin>;
    _____________________________________________
    I then double clicked on the name and got the dos flicker .. but no file was
    created.

    so problem continues ... (new computer Windows XP .. and newly downloaded
    ActivePerl seemingly sucessfully installed. )

    Roy bramblet @ telus.net remove spaces.

    ----- Original Message -----
    From: "Jürgen Exner" <>
    Newsgroups: comp.lang.perl,comp.lang.perl.misc
    Sent: Monday, December 18, 2006 8:05 AM
    Subject: Re: Question from perl newbie


    > [X-Post and follow-up to CLPM because CLP has been a zombie for many
    > years, please see the FAQ]
    >
    > Victor wrote:
    >> I downloaded and installed Perl, seemingly in a successful manner to a
    >> Windows XP computer. then I wrote the following code to a file,
    >> Example_4_1.pl:
    >>
    >> #! ..\bin\perl -w

    >
    > Windows doesn't care about the shebang line. You can just as well leave it
    > out.
    > The command line option -w is outdated. It is better to use
    > use warnings;
    > instead.
    >
    >> $DNA = 'abc' ;
    >> print $DNA ;
    >> exit ;

    >
    > If exit is the last statement and you are not returning any special value
    > then you may just as well omit it.
    >
    >> Then, I run:
    >>
    >>> perl Example_4_1.pl

    >
    > Normally your Perl installation should have associated the .pl extension
    > with the Perl interpreter, such that you can run any Perl program by just
    > typing its name without calling the interpreter directly.
    >
    > Example_4_1.pl
    >
    >> The program seems to run without complaints, yet I don't see the
    >> output of the print statement. What do I need to do to be able to
    >> see the output?

    >
    > That is weird. There is nothing wrong with your Perl code.
    > Maybe someone in CLPM knowns.
    >
    > jue
    >
    Roy Jaffray, Feb 16, 2007
    #4
  5. Roy Jaffray wrote:
    > am a newbie as well .. with exactly the same problem.
    >
    > I have a file called "helloworld.pl". When it wouldnt put out any
    > output using <stdin> I decided to try to create and open a file and
    > write to that.
    > ____helloworld.pl________________________________


    You are missing
    use strict;
    use warnings;

    > open(geo,">perltest.txt") or die ("Cannot Open perltest.txt");


    It would be better to include the reason why the open failed.
    .... or die ("Cannot Open perltest.txt because $!");
    >
    > for ($loop_index =1; $loop_index <=5; $loop_index++)


    What's wrong with
    for $loop_index (1..5)
    Much easier to read

    > {
    > Print geo "hello world!\n"


    Where to you define the funtion Print()?

    > }
    > Print "there!\n\n\n"


    Where do you define the function Print()?

    > close (geo);
    > print "Press <enter> to continue" ;
    > <stdin>;
    > _____________________________________________
    > I then double clicked on the name and got the dos flicker .. but no
    > file was created.


    Well, yeah, sure. Why don't you fix that syntax error that perl is telling
    you about?

    String found where operator expected at C:\tmp\t.pl line 8, near "Print
    "there!\
    n\n\n""
    (Do you need to predeclare Print?)
    syntax error at C:\tmp\t.pl line 8, near "Print "there!\n\n\n""
    Execution of C:\tmp\t.pl aborted due to compilation errors.

    > so problem continues ... (new computer Windows XP .. and newly
    > downloaded ActivePerl seemingly sucessfully installed. )


    Irrelevant. Your Perl code has a syntax error. Of course it doesn't produce
    anything because it never even passed the syntax check.

    jue
    Jürgen Exner, Feb 16, 2007
    #5
  6. Victor

    Joe Smith Guest

    Roy Jaffray wrote:
    > am a newbie as well .. with exactly the same problem.
    >
    > ____helloworld.pl________________________________


    > I then double clicked on the name and got the dos flicker .. but no file was
    > created.


    Whenever clicking does not work, you should try running it from
    the command line.

    Start -> Run -> cmd
    C:\> perl helloworld.pl

    Fix the problems there first.
    -Joe
    Joe Smith, Feb 18, 2007
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dpackwood
    Replies:
    3
    Views:
    1,794
  2. Jerry C.
    Replies:
    8
    Views:
    229
    Uri Guttman
    Nov 23, 2003
  3. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Jan 23, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    298
    PerlFAQ Server
    Jan 23, 2011
  4. PerlFAQ Server
    Replies:
    0
    Views:
    677
    PerlFAQ Server
    Feb 3, 2011
  5. PerlFAQ Server

    FAQ 1.4 What are Perl 4, Perl 5, or Perl 6?

    PerlFAQ Server, Feb 27, 2011, in forum: Perl Misc
    Replies:
    0
    Views:
    294
    PerlFAQ Server
    Feb 27, 2011
Loading...

Share This Page