Basic Perl Questions
Hi All, I have some Perl experience but has been awhile. I mainly write SKILL lisp programs for Cadence CAD for a layout group(we are a IC design center). I have a CBR(describes circuit) file and want to open it, find the line in file .SUBCKT __RE1321_4 HB_GND GSM_RX DCS_RX DCS_VRX GSM_VRX PCS_TX SHUNT_GND ANT +VRXEN GSM_VTX GSM_TX PCS_VTX Where .SUBCKT __RE1321_4 is found and the output of the file is the pins(ignore the + sign) Output: ("HB_GND" "GSM_RX" "DCS_RX" "DCS_VRX" "The rest of 'em") The above is a list that can be used by SKILL code. I only understand the very basics of perl, the more info the better. Thank you in advance for any help, Eric What I have so far. #!/usr/bin/perl use warnings; use strict; my $read_file = 'RE1321_4.cbr'; my $write_file = 'NavInputPins.list'; open READ, '<', $read_file or die "Can't open '$read_file' $!"; open WRITE, '>', $write_file or die "Can't open '$write_file' $!"; } close READ or die "Couldn't close '$read_file' $!"; close WRITE or die "Couldn't close '$write_file' $!"; exit 0; __END__ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Basic Perl Questions
On 2/3/10 Wed Feb 3, 2010 6:44 AM, "PolyPusher" scribbled: > Hi All, > > I have some Perl experience but has been awhile. I mainly write > SKILL lisp programs for Cadence CAD for a layout group(we are a IC > design center). > > I have a CBR(describes circuit) file and want to open it, find the > line in file > > .SUBCKT __RE1321_4 HB_GND GSM_RX DCS_RX DCS_VRX GSM_VRX PCS_TX > SHUNT_GND ANT > +VRXEN GSM_VTX GSM_TX PCS_VTX > > Where .SUBCKT __RE1321_4 is found and the output of the file is the > pins(ignore the + sign) > > Output: > ("HB_GND" "GSM_RX" "DCS_RX" "DCS_VRX" "The rest of 'em") > > The above is a list that can be used by SKILL code. > > I only understand the very basics of perl, the more info the better. > > Thank you in advance for any help, > Eric > > What I have so far. You have a good start. My additions below are untested, so may contain bugs. > > #!/usr/bin/perl > use warnings; > use strict; > > > my $read_file = 'RE1321_4.cbr'; > my $write_file = 'NavInputPins.list'; > > > open READ, '<', $read_file or die "Can't open '$read_file' $!"; > open WRITE, '>', $write_file or die "Can't open '$write_file' $!"; > while( my $line = ) { if( $line =~ m{ \A \.SUBCKT }x ) { my @fields = split(' ',$line); my @pins = grep( !/\+/, @fields[ 2 .. $#fields] ); print WRITE '"', join('" "',@pins), "\"\n"; } > } > > > close READ or die "Couldn't close '$read_file' $!"; > close WRITE or die "Couldn't close '$write_file' $!"; > > exit 0; > > > __END__ > -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Basic Perl Questions
PolyPusher wrote: Hi All, Hello, I have some Perl experience but has been awhile. I mainly write SKILL lisp programs for Cadence CAD for a layout group(we are a IC design center). I have a CBR(describes circuit) file and want to open it, find the line in file Is it just one line or are there multiple lines that match? .SUBCKT __RE1321_4 HB_GND GSM_RX DCS_RX DCS_VRX GSM_VRX PCS_TX SHUNT_GND ANT +VRXEN GSM_VTX GSM_TX PCS_VTX Where .SUBCKT __RE1321_4 is found and the output of the file is the pins(ignore the + sign) Ignore the + sign because? Does it signify a continuation character with the remaining pins on the next line? Output: ("HB_GND" "GSM_RX" "DCS_RX" "DCS_VRX" "The rest of 'em") The above is a list that can be used by SKILL code. I only understand the very basics of perl, the more info the better. Thank you in advance for any help, Eric What I have so far. #!/usr/bin/perl use warnings; use strict; my $read_file = 'RE1321_4.cbr'; my $write_file = 'NavInputPins.list'; open READ, '<', $read_file or die "Can't open '$read_file' $!"; open WRITE, '>', $write_file or die "Can't open '$write_file' $!"; All you need here is a while loop to read lines and print out the results. If your "line" is actually two lines then you need to handle that as well. If you are only looking for the one line then you can exit the loop as soon as you find it instead of reading through the entire file. Provide some more information and it should be easy to write. close READ or die "Couldn't close '$read_file' $!"; close WRITE or die "Couldn't close '$write_file' $!"; exit 0; __END__ John -- The programmer is fighting against the two most destructive forces in the universe: entropy and human stupidity. -- Damian Conway -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Re: Basic Perl Questions
On Feb 3, 2:26 pm, jwkr...@shaw.ca ("John W. Krahn") wrote: > PolyPusher wrote: > > Hi All, > > Hello, > > > I have some Perl experience but has been awhile. I mainly write > > SKILL lisp programs for Cadence CAD for a layout group(we are a IC > > design center). > > > I have a CBR(describes circuit) file and want to open it, find the > > line in file > > Is it just one line or are there multiple lines that match? > > > .SUBCKT __RE1321_4 HB_GND GSM_RX DCS_RX DCS_VRX GSM_VRX PCS_TX > > SHUNT_GND ANT > > + VRXEN GSM_VTX GSM_TX PCS_VTX > > > Where .SUBCKT __RE1321_4 is found and the output of the file is the > > pins(ignore the + sign) > > Ignore the + sign because? Does it signify a continuation character > with the remaining pins on the next line? > > > > > > > Output: > > ("HB_GND" "GSM_RX" "DCS_RX" "DCS_VRX" "The rest of 'em") > > > The above is a list that can be used by SKILL code. > > > I only understand the very basics of perl, the more info the better. > > > Thank you in advance for any help, > > Eric > > > What I have so far. > > > #!/usr/bin/perl > > use warnings; > > use strict; > > > my $read_file = 'RE1321_4.cbr'; > > my $write_file = 'NavInputPins.list'; > > > open READ, '<', $read_file or die "Can't open '$read_file' $!"; > > open WRITE, '>', $write_file or die "Can't open '$write_file' $!"; > > All you need here is a while loop to read lines and print out the > results. If your "line" is actually two lines then you need to handle > that as well. If you are only looking for the one line then you can > exit the loop as soon as you find it instead of reading through the > entire file. Provide some more information and it should be easy to write. > > > close READ or die "Couldn't close '$read_file' $!"; > > close WRITE or die "Couldn't close '$write_file' $!"; > > > exit 0; > > > __END__ > > John > -- > The programmer is fighting against the two most > destructive forces in the universe: entropy and > human stupidity. -- Damian Conway- Hide quoted text - > > - Show quoted text - John, Jim, I will repost as I have learned of some more issues to overcome. Thank you for your help! PolyPusher -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/
Some few basic Perl questions
Hiya, I got some basic Perl questions. Hope you don't mind answerring them? 1) What is the use of just putting $var; on 1 line? Example: #!usr/bin/perl -wT # some code $var; Does this technique rescopes the variable? 2) Why is exit() or 1; used on the LAST line. I understand it being on some line when you need to exit. Also, exit() won't be too hard. I think (and I think I am possibly right), it exits because there are still some operations during. But why 1; on the end of the line? Does it wait for a true value of the whole script? Think I've kinda missed these usements on Perl ;-) Thanks for your help, already. _ Direct chatten met je vrienden met MSN Messenger http://messenger.msn.nl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: Some few basic Perl questions
Hi - Putting a value or variable alone on the last line of a scope like: sub something { blah, blah, blah... ... 1; } implies 'return 1;'. The subroutine (or scope) returns the value last evaluated. The function 'exit' or 'exit 99' does just that, exits the script to the os (or whoever called it with 'system' or ``) with the return code given. Aloha => Beau. PS: As an old-time c/c++ programmer this confused me too in my earlier days with perl. -Original Message- From: Mystik gotan [mailto:[EMAIL PROTECTED]] Sent: Saturday, November 23, 2002 11:19 AM To: [EMAIL PROTECTED] Subject: Some few basic Perl questions Hiya, I got some basic Perl questions. Hope you don't mind answerring them? 1) What is the use of just putting $var; on 1 line? Example: #!usr/bin/perl -wT # some code $var; Does this technique rescopes the variable? 2) Why is exit() or 1; used on the LAST line. I understand it being on some line when you need to exit. Also, exit() won't be too hard. I think (and I think I am possibly right), it exits because there are still some operations during. But why 1; on the end of the line? Does it wait for a true value of the whole script? Think I've kinda missed these usements on Perl ;-) Thanks for your help, already. _ Direct chatten met je vrienden met MSN Messenger http://messenger.msn.nl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Some few basic Perl questions
i'm unsure about the first question, but your answer to the 2nd one, is, if you are using more than 1 script in your program, and you require() it, the script that's require()'d must have 1; as the last line. this way, perl knows it's the end of the file, and not to read any further. it returns a "true value" to perl. it also claims to perl that the script is complete. dan "Mystik Gotan" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > Hiya, > > I got some basic Perl questions. Hope you don't mind answerring them? > > 1) What is the use of just putting $var; on 1 line? Example: > #!usr/bin/perl -wT > > # some code > $var; > > Does this technique rescopes the variable? > 2) Why is exit() or 1; used on the LAST line. I understand it being on some > line when you need to exit. Also, exit() won't be too hard. I think (and I > think I am possibly right), it exits because there are still some operations > during. But why 1; on the end of the line? Does it wait for a true value of > the whole script? > > Think I've kinda missed these usements on Perl ;-) > > Thanks for your help, already. > > > > _ > Direct chatten met je vrienden met MSN Messenger http://messenger.msn.nl > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: Some few basic Perl questions
From: "Mystik gotan" <[EMAIL PROTECTED]> > Hiya, > > I got some basic Perl questions. Hope you don't mind answerring them? > > 1) What is the use of just putting $var; on 1 line? Example: > #!usr/bin/perl -wT > > # some code > $var; > > Does this technique rescopes the variable? No. It doesn't do anything. (Unless the $var variable is tie()d to something. See perltie manpage if feeling adventurous.) > 2) Why is exit() or 1; used on the LAST line. I understand it being on > some line when you need to exit. Also, exit() won't be too hard. I > think (and I think I am possibly right), it exits because there are > still some operations during. But why 1; on the end of the line? Does > it wait for a true value of the whole script? The exit() or exit(number) simply exits the script, no matter how deep in the function calls or loops you are. The 1; is used in modules or snipets of code that are supposed to be use()d, require()d or do()ne. The 1; tells Perl that the module/code was loaded fine. This is because of a very rarely used feature ... if you use some conditional expression or a variable or something instead of the 1; then the expression would be evaluated and if it returns a false value Perl will exit with an error message. For example if the module only works under WinNT/Win2k/WinXP and not under Win9x it may end with something like: Win32::IsWinNT(); And if you try to use it under Win9x you'll get something like: did not return a true value at line HTH, Jenda = [EMAIL PROTECTED] === http://Jenda.Krynicky.cz = When it comes to wine, women and song, wizards are allowed to get drunk and croon as much as they like. -- Terry Pratchett in Sourcery -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]