This is the P2PU Archive. If you want the current site, go to www.p2pu.org!

Scripting 101

Chat log Class 8

hemanth hm's picture
Sun, 2010-10-10 18:38

nmort> Hello all!
<hemanth> nmort, hello
* hemanth is bit unwell today
<hemanth> :(
<nmort> what's wrong?
<hemanth> slammed to a door!
<nmort> ouch!
<hemanth> right hand hurts now
<hemanth> it didn't hurt at that moment
<nmort> not good
* vibha6bhat (75c0cf01@gateway/web/freenode/ip.117.192.207.1) has joined #p2pu-webcraft/scripting-101
<hemanth> its the muscle thats paining
<hemanth> so not a broken bone for sure
<nmort> its good that is wasn't a bone
<nmort> so you shouldn't be typing if your hand hurts
<hemanth> yes, today i will just brief exceptions in ruby and perl at let the class...hmm..
<hemanth> some refile spray might help
<hemanth> hey vibha6bhat
<hemanth> hows it going?
<vibha6bhat> Quite good
<hemanth> lets wait for a min and start
<vibha6bhat> okay
<nmort> hemanth do you know of any good sites with exercises for scripting?
<hemanth> hmm...exercises
<hemanth> hang on
<hemanth> nmort, http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_01_07.html
* PaBLoX (~arch@186.104.154.77) has joined #p2pu-webcraft/scripting-101
<PaBLoX> Hi
<PaBLoX> I'll be here in a minute
<PaBLoX> My kid is having lunch right now :P
<hemanth> nice :)
<PaBLoX> btw, limpid is not working :'(
<hemanth> issue??
<PaBLoX> you just started right?
<hemanth> yes might end soon
<nmort> hemanth thanks, any for the other languages?
<hemanth> nmort, not as of now :)
* PaBLoX_ (ba689a4d@gateway/web/freenode/ip.186.104.154.77) has joined #p2pu-webcraft/scripting-101
* PaBLoX has quit (Client Quit)
<nmort> ok, no problem
<PaBLoX_> why are we going to end soon?
<hemanth> PaBLoX_, sent u a quick paste
<hemanth> yesterday we noted in python errors and exceptions, the keywords to be noted were 'raise','try','expect','finally'
* hemanth has changed the topic to: RUBY and PERL exceptions
<hemanth> btw class, hobs said:"I cant make the classes due to work scheduling"
<hemanth> SourRust,Adams and others are missing today
<hemanth> So in Ruby the keywords => raise, rescue, ensure
<hemanth> and in PERL => die, try { a CATCH exn { ... } },
<hemanth> in PERL its just try catch and die, there is not finally kina construct
<hemanth> Ruby example :
<hemanth> f = File.open("testfile")
<hemanth> begin
<hemanth>  # .. process
<hemanth> rescue
<hemanth>  # .. handle error
<hemanth> else
<hemanth>  puts "Congratulations-- no errors!"
<hemanth> ensure
<hemanth>  f.close unless f.nil?
<hemanth> end
<hemanth> Can that be correlated to yestd py?
<nmort> Errno:: ENOENT: No such file
<nmort> am I doing something wrong?
<hemanth> nmort,no, not at all
<hemanth> as testfile is not present
<hemanth> you are getting that
<hemanth> that must be handled in the rescue block
<hemanth> where you see the comment # .. handle error
<hemanth> there you can print your own error or the same and exit
<hemanth> what i showed now, is just a template
<nmort> ok
<hemanth> using which you will be pushing the code to the repo
<hemanth> in PERL
<hemanth> open(FILE, $file) ||  die ("Unable to open file - $file");
<PaBLoX_> well, that sounds simple
<PaBLoX_> considering is perl
<PaBLoX_> :S
<hemanth> he he
<hemanth> die is it?
<hemanth> PERL uses a eval block to make things more cleaner like
<hemanth> eval {
<hemanth>   # Code that could throw an exception (using 'die')
<hemanth>   1;
<hemanth> } or do {
<hemanth>   # Handle exception here. The exception string is in $@
<hemanth> }
<hemanth> So, the final generic code for ruby in the same lines will be like
<hemanth> begin
<hemanth>   # Do something nifty
<hemanth>   raise SomeError, "This is the error message!"  # Uh-oh!
<hemanth> rescue SomeError
<hemanth>   # This is executed when a SomeError exception
<hemanth>   # is raised
<hemanth> rescue AnotherError => error
<hemanth>   # Here, the exception object is referenced from the
<hemanth>   # `error' variable
<hemanth> rescue
<hemanth>   # This catches all exceptions derived from StandardError
<hemanth>   retry # This executes the begin section again
<hemanth> else
<hemanth>   # This is executed only if no exceptions were raised
<hemanth> ensure
<hemanth>   # This is always executed, exception or not
<hemanth> end
<hemanth> $@ in PERL in the try block contains the value passed from die
<hemanth> queries so far?
<PaBLoX_> nope
<PaBLoX_> everything clear
<PaBLoX_> I don't like perl though
<PaBLoX_> :P
<nmort> clear
<hemanth> ya, these are just the templates, once you try them u will come with doubts for sure
<hemanth> So, it was a very quick session, today, sorry about that
<hemanth> but considering yestd, base to Errors and Exceptions
<hemanth> the templates must make some scene
<hemanth> do push the code, make threads in the forums with doubts
<hemanth> and do share links as PaBLoX_ has already started doing it :)
<hemanth> cay all next week
* hemanth gets some ice pack
<nmort> bye
<nmort> take care
<hemanth> thanks
<PaBLoX_> hey
<PaBLoX_> do you have a second?
<hemanth> yes
<PaBLoX_> i'm having a weird trouble with the class bash script
<hemanth> shoot it
<PaBLoX_> date: invalid date «next saturday»
<PaBLoX_> date: invalid date «next sunday»
<hemanth> PaBLoX_, you don't have GNU date with you
<hemanth> on which OS are you?
<PaBLoX_> I do have
<PaBLoX_> im on arch linux
<PaBLoX_> and "date" works
<PaBLoX_> $date dom oct 10 13:06:59 CLST 2010
<hemanth> $ date --version
<hemanth> says what?
<hemanth> GNU date is what is required
<PaBLoX_> date (GNU coreutils) 8.5 Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.  Escrito por David MacKenzie.
<PaBLoX_> I was actually working
<PaBLoX_> In facr
<PaBLoX_> Yesterday it worked
<PaBLoX_> today was the "time change"
<PaBLoX_> (now we are utc -3)
<hemanth> strange!
<hemanth> can u pastebin the script?
<PaBLoX_> yeah, really strange
<PaBLoX_> in fact
<PaBLoX_> the command
<PaBLoX_> date -d "next saturday"
<PaBLoX_> gave me an error
<hemanth> date -d "next saturday" +%Y-%m-%d
<hemanth> gives an error as?
<PaBLoX_> http://pablox.pastebin.com/rLmphGMs
<PaBLoX_> the same kind of error
<PaBLoX_> invalid date
<PaBLoX_> :s
<hemanth> do
<hemanth> which date
<hemanth> date --version is saying GNU
<hemanth> so that must be fine
<hemanth> PaBLoX_, there is one such similar bug report http://savannah.gnu.org/bugs/?11687
<PaBLoX_> but that's from 2005 :s
<hemanth> PaBLoX_,reoccurred again!
<hemanth> locale
<hemanth> what does it say?
<hemanth> LC_TIME="en_IN"
<hemanth> LC_TIME="en_US"
<hemanth> something like that?
<PaBLoX_> LC_TIME="es_CL.UTF-8"
<PaBLoX_> (besides other LC_*)
<hemanth> try LC_TIME="en_US"
<hemanth> if not bug report on GNU
<hemanth> do check arch forums
<PaBLoX_> hm
<PaBLoX_> the same
<PaBLoX_> what i don't understand
<PaBLoX_> is that yesterday it was working
<PaBLoX_> stopped working today
<hemanth> PaBLoX_, cant type more; do trackback wht all did u install yestd
<PaBLoX_> hm
<PaBLoX_> I believe nothing, that's the weirdest thing in the worl
<PaBLoX_> d
<PaBLoX_> no no
<PaBLoX_> im looking at the pacman log
<PaBLoX_> http://pablox.pastebin.com/HmB4MJu0
<PaBLoX_> weel
<PaBLoX_> if you're busy let's speak later
<PaBLoX_> =)
<PaBLoX_> hey
<hemanth> PaBLoX_, seems so locale mess up, will catch u later cya
<PaBLoX_> yes
<PaBLoX_> it's the timezone
<PaBLoX_> I changed the TIMEZONE
* hemanth takes feel pain killers :D
<PaBLoX_> and now it works
<PaBLoX_> :s
<hemanth> nice
* vibha6bhat has quit (Quit: Page closed)
<PaBLoX_> hemanth: weird, I changed something in the locale and now it's working fine:/
<PaBLoX_> hemanth: bye bye, see ya next week =)