Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

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

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

  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or or How to display code and escape characters are good places to start.
Log In?

What's my password?
Create A New User
Domain Nodelet?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2021-12-04 02:15 GMT
Find Nodes?
    Voting Booth?
    R or B?

    Results (30 votes). Check out past polls.