Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Hello, I am asking for assistance from any monk wandering by this place of solitude and confusion. I am new, and I am working on an exercise problem I have created for myself from various sources. I have perused the halls of the monks, google, the cookbook (Which got me closer to my idea of a goal) and Learning Perl.

I wish to add a default value to my script and I do not understand how to apply it to the script. The file I am looking to open is called somelist. (disclaimer): It's hard for me to see some things, so my semi colons are in odd locations for now, so I can readily see where they are , and if any are missing. At this point in time, that is pretty helpful to me. So please be patient. Here is the script.

#!/usr/local/bin/perl print "\n" ; print "Which file do you want to open? " ; # we are asking which file + to open $file0 = <STDIN> ; $file = $file0 || "somelist"; #here's my effort to apply a default t +o the input if it is blank. # THIS IS WHAT I WOULD LIKE TO DO -> if stdin is blank, i'd like to as +sign $file a variable. chomp($file) ; # print "\n" ; print "Which driver do you want to see? " ; # we are asking to output + info from a particular line chomp ($name = <STDIN>) ; # the more idiomatic way # Our requested file is accessed and displayed $bibfile = "$file" ; open (IN, "<$bibfile") or die "Can't open $bibfile\n"; print "File Contents:\n" ; while ($line = <IN>) { chomp($line) ; ($Drivers,$Points_Rank,$TotalPts,$Behind,$Starts,$Poles,$Wins,$Top5, +$Top10,$DNF,$Winnings) = split /\,/, $line; if ($Drivers=~ m/$name/i) { print " $Drivers, $Points_Rank, $Top10, $Wins, $Starts, $DNF \n"; } # } close IN ;
Yes, I'm a nascar fan. I can't help it.. I got hit in the head. SO anyway, when I apply the default, all it says is "Can't open". BUT if I pull out my attempt to add a default variable, this script works fine.

My real issue is that though I've seen the different types of default value examples, I do not know how to apply them to a script properly. In particular, this script.

My real learning curve comes from seeing examples applied, rather than reading the definitions of things, hence, my mental block. Thank you for your time.


In reply to Adding Default Values [for BEGINNERS] by brusimm

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and all is quiet...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (5)
    As of 2018-07-17 00:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      It has been suggested to rename Perl 6 in order to boost its marketing potential. Which name would you prefer?















      Results (353 votes). Check out past polls.

      Notices?