RiskiiDingo has asked for the wisdom of the Perl Monks concerning the following question:

I cannot get this program to print in konsol and I do not understand where I've gone wrong.

I'm new to this so I'm sure its something simple but I can't spot it...

#!/usr/bin/perl use strict; use warnings; #Open up the data and read it to program my ( $data, $transType, $accNumber); open FILE, "sampleTransactions01.dat" or die$!; $data = <FILE>; my @values = split(',|\(', $data); #assign the data a name $transType=$values[0]; $accNumber=$values[1]; #Printing data # print "***************************************************\n Transaction Type:$transType\n Account Number:$accNumber\n ***************************************************\n"

Replies are listed 'Best First'.
Re: Can't get text to print
by choroba (Cardinal) on Oct 20, 2014 at 10:38 UTC
    Hi RiskiiDingo, welcome to the Monastery!

    Do you mean there is no output at all? I doubt it, when I run the program with an empty input file, I still get some output (with no values filled in).

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
Re: Can't get text to print
by vinoth.ree (Monsignor) on Oct 20, 2014 at 10:44 UTC
    Hi RiskiiDingo

    I have tested your code with sample input in the file as This,is,testing and I am getting output as below

    *************************************************** Transaction Type:this Account Number:is ***************************************************

    So could you please check your input file is non empty and if not empty please post us the sample contents of the input file.


    All is well
Re: Can't get text to print
by LanX (Saint) on Oct 20, 2014 at 10:37 UTC
    Nothing is printed? No stars at all?

    That's the complete and tested script?

    update
    Your open is wrong considered bad practice, the < MODE is missing.

    Cheers Rolf

    (addicted to the Perl Programming Language and ☆☆☆☆ :)

    update

    updated update :)

      I hope, If the mode is missing by default the file takes the default mode that is "<" (read only) mode.


      All is well

        from the linked documentation:

        "If MODE is < or nothing, the file is opened for input."

        Update: Intended as response to pre-update version of Re: Can't get text to print and misplaced. Mea culpa. </update>

        From http://perldoc.perl.org/functions/open.html (5.20)

        If three (or more) arguments are specified, the open mode (including optional encoding) in the second argument are distinct from the filename in the third. If MODE is < or nothing, the file is opened for input.

        i.e., opened for reading. And also:

        In the one- and two-argument forms of the call (emphasis supplied) ... (y)ou can--but shouldn't--omit the mode in these forms when that mode is < .


        check Ln42!

Re: Can't get text to print
by ww (Archbishop) on Oct 20, 2014 at 13:23 UTC

    What warnings or error messages are you seeing? (Makes helping you easier/possible)
    Are you sure (IOW, have you tested) that Ln 6 (looks funky) performs as intended?
    And, as requested by others, sample data please!



    Questions containing the words "doesn't work" (or their moral equivalent) will usually get a downvote from me unless accompanied by:
    1. code
    2. verbatim error and/or warning messages
    3. a coherent explanation of what "doesn't work actually means.