[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

gets give me last arg of script ???

pere.noel

8/12/2006 10:14:00 AM


something i don't understand : gets give me last arg of script ???

here is part of my script :

------------------------------------------------------------------------
def get_respons
return (/^[y|Y|O|o].*/ === gets.to_s.chomp)
end

dir_path=Dir.pwd
dir_path=$*[0] if $*.length == 1
puts "Are you sure you want to convert #{dir_path} ?[y|Y|O|o/n] default
to NO"
if get_respons
puts "reponse YES"
end
------------------------------------------------------------------------

and the script (being in my $PATH) is called from terminal :
> set_date /Users/yvon

and the message error i get is :
> set_date /Users/yvon
Are you sure you want to convert /Users/yvon ?[y|Y|O|o/n] default to NO
nil
/Users/yvon/bin/set_date:7:in `gets': Is a directory - /Users/yvon
(Errno::EISDIR)
from /Users/yvon/bin/set_date:7:in `get_reponse'
from /Users/yvon/bin/set_date:17

line 7 being "return (/^[y|Y|O|o].*/ === gets.to_s.chomp)"
and 17 the call to "get_respons" : "if get_respons"

notice the $*[0] is allready used in my script ???
--
une bévue
4 Answers

ts

8/12/2006 1:39:00 PM

0

>>>>> "U" == Une bévue <pere.noel@laponie.com.invalid> writes:

U> something i don't understand : gets give me last arg of script ???

It's normal : it make the right thing.


moulon% ri Kernel#gets
------------------------------------------------------------ Kernel#gets
gets(separator=$/) => string or nil
------------------------------------------------------------------------
Returns (and assigns to +$_+) the next line from the list of files
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
in +ARGV+ (or +$*+), or from standard input if no files are present
^^^^^^^^^^^^^^^^^^
on the command line. Returns +nil+ at end of file. The optional
[...]
moulon%

U> notice the $*[0] is allready used in my script ???

This is bad : $ variables must not be used, it's best to use ARGV.

ARGV[0] is used but was *not* removed from ARGV

Try this

moulon% ruby -e 'p ARGV[0]; p gets' inexistant
"inexistant"
-e:1:in `gets': No such file or directory - inexistant (Errno::ENOENT)
from -e:1
moulon%

moulon% ruby -e 'p ARGV.shift; p gets' inexistant
"inexistant"
Bonjour
"Bonjour\n"
moulon%



--

Guy Decoux

Logan Capaldo

8/12/2006 1:46:00 PM

0


On Aug 12, 2006, at 6:15 AM, Une bévue wrote:

>
> something i don't understand : gets give me last arg of script ???
>
> here is part of my script :
>
> ----------------------------------------------------------------------
> --
> def get_respons
> return (/^[y|Y|O|o].*/ === gets.to_s.chomp)
> end
>
> dir_path=Dir.pwd
> dir_path=$*[0] if $*.length == 1
> puts "Are you sure you want to convert #{dir_path} ?[y|Y|O|o/n]
> default
> to NO"
> if get_respons
> puts "reponse YES"
> end
> ----------------------------------------------------------------------
> --
>
> and the script (being in my $PATH) is called from terminal :
>> set_date /Users/yvon
>
> and the message error i get is :
>> set_date /Users/yvon
> Are you sure you want to convert /Users/yvon ?[y|Y|O|o/n] default
> to NO
> nil
> /Users/yvon/bin/set_date:7:in `gets': Is a directory - /Users/yvon
> (Errno::EISDIR)
> from /Users/yvon/bin/set_date:7:in `get_reponse'
> from /Users/yvon/bin/set_date:17
>
> line 7 being "return (/^[y|Y|O|o].*/ === gets.to_s.chomp)"
> and 17 the call to "get_respons" : "if get_respons"
>
> notice the $*[0] is allready used in my script ???
> --
> une bévue
>

Kernel#gets (what you get when you just use gets) calls ARGF.gets.
ARGF is a magic IO object that lets your script have a cli api
similar to apps like 'cat'. You can check the docs for details, but
basically what you want to use is $stdin.gets or STDIN.gets not plain
old gets



pere.noel

8/12/2006 3:01:00 PM

0

Logan Capaldo <logancapaldo@gmail.com> wrote:

>
> Kernel#gets (what you get when you just use gets) calls ARGF.gets.
> ARGF is a magic IO object that lets your script have a cli api
> similar to apps like 'cat'. You can check the docs for details, but
> basically what you want to use is $stdin.gets or STDIN.gets not plain
> old gets

ok fine thanks ;-)
--
une bévue

CB

9/24/2008 6:59:00 PM

0

Hi Dan,

I apologize for taking so long to reply - not sure where the time went...

"dan dungan" wrote:

> Hi Chris,
>
> I'm not quite clear.
>
> >In a way it seems counter-intuitive to me to put it in
> >Privat Sub Workbook_Open() as that code is checking
> >if the sheet has autofilter on and if not
> >enabling autofilter then protecting the sheet.
>
> Which sheet are you trying to unprotect?

The four indicated in the code below.

>
> In your initial post you wrote:
>
> >I would like it if somehow I could enter the data into the
> >protected worksheet without having to unprotect each worksheet first.
>
> How many worksheets do you need to unprotect?

I have four worksheets that I need to be able to unprotect (which remained
protected for anyone else).

>
> >Ideally, I would like it if somehow the software would recognize
> >it is me and unprotect everything then reinforce protection
> >when I am done updating.
>
> How are the worksheets being protected, manually or by code?
> What version of Excel are you using?
> What type of Excel file are you using? xls? xlt?
>

The worksheets are being protected by code. I am using Excel 2003 and the
files are not templates (i.e., they are .xls not .xlt). I posted my code in
another message in this newgroup but I'm copying it below for your reference.

...........
Sub Workbook_Open()

'check for filter, turn on if none exists

With Worksheets("Depot_Inventory_Serialized")
If Not .AutoFilterMode Then
.Range("B2").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="myPW", _
Contents:=True, UserInterfaceOnly:=True
End With

With Worksheets("Warehouse_Inventory_Serialized")
If Not .AutoFilterMode Then
.Range("B2").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="myPW", _
Contents:=True, UserInterfaceOnly:=True
End With

With Worksheets("Depot_Inventory_non-Serial")
If Not .AutoFilterMode Then
.Range("B5").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="myPW", _
Contents:=True, UserInterfaceOnly:=True
End With

With Worksheets("Warehouse_Inventory_non-Serial")
If Not .AutoFilterMode Then
.Range("B5").AutoFilter
End If
.EnableAutoFilter = True
.Protect Password:="myPW", _
Contents:=True, UserInterfaceOnly:=True

End With

End Sub
.......................


> >Since I???m updating the workbook every week or two,
> >I don???t want to have to update my version, make a copy,
> >add in the code for protection and autofiltering,
> >then place that copy on the network.
>
> What stops you from keeping your copy on the network?
> I don't understand why you need to copy "your" version.
>

There are two supervisors that need to open the workbook, look at the data
and use autofilters. I do not want them to accidentally change/delete data so
I protected everything, which is sufficient for their use.

The thing though is that the workbook/worksheets are still protected when I
open the file. When I need to add data, I have to unprotect each worksheet
first. I can do that but I was looking assistance with code that would allow
me to bypass that step.

I had found code within the Excel newsgroups that worked for the user who
originally posted the message but it does not appear to work for me since I
still have to go through the process of unprotecting the worksheets.

Additionally, when I???m viewing the code and Run Sub/User Form I get
???Run-time error ???1004??? Application-defined or object-defined error.???

Hence, my original post.

Chris


> Dan
>