brusimm has asked for the wisdom of the Perl Monks concerning the following question:
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.
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.#!/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 ;
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.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Adding Default Values [for BEGINNERS]
by ikegami (Patriarch) on Dec 21, 2006 at 22:52 UTC | |
Re: Adding Default Values [for BEGINNERS]
by GrandFather (Saint) on Dec 21, 2006 at 22:50 UTC | |
Re: Adding Default Values [for BEGINNERS]
by OfficeLinebacker (Chaplain) on Dec 21, 2006 at 22:54 UTC | |
Re: Adding Default Values [for BEGINNERS]
by ikegami (Patriarch) on Dec 21, 2006 at 22:57 UTC | |
Re: Adding Default Values [for BEGINNERS]
by brusimm (Pilgrim) on Dec 21, 2006 at 23:27 UTC | |
by GrandFather (Saint) on Dec 21, 2006 at 23:40 UTC | |
by syphilis (Archbishop) on Dec 22, 2006 at 00:33 UTC | |
by brusimm (Pilgrim) on Dec 22, 2006 at 20:39 UTC |