http://qs1969.pair.com?node_id=591210

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

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.