Re: Ragged Hierarchy
On 12/20/07, banker123 <[EMAIL PROTECTED]> wrote: > I have two started the first is my attempt to read the file into an > array, the second is processing each variable. I am unsure how to > identify the last variable in a variable length line of data. > > open (input, 'c:\organization.txt') or die "Cannot open file: $!"; It's generally good practice to use all caps for filehandle names, or to use lexical variables. Also, for a number of reasons, it's better to use forward slashes instead of backslashes in literal filenames. So I'd probably re-write that code something like this, and change the rest of the code accordingly: open my $input, "c:/organization.txt" or die "Can't open file: $!"; > open ('input', 'c:\organization.txt') or die "Cannot open file: $!"; > open ('output', '>C:/out.txt') or die "Cannot open file: $!"; I'm not sure what you're trying to do here; didn't you already open your input filehandle? But using strings as filehandle names like that is discouraged. > my > ($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19,$v20,$v21,$v22,$v23,$v24) > = split (/,/); Ouch! Using many numbered variables is a warning sign that a data structure is needed. In this case, an array could make your life much simpler. After using split() into an array, the problem of identifying the last element's index is easy; it's the last valid index of the array. my @v = split /,/, $_; my $last_elem_index = $#v; Does that get you closer to a solution? Good luck with it! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Ragged Hierarchy
Here is what I have: open ('input', 'C:/Organization.txt') or die "Cannot open file: $!"; open ('output', '>C:/out.txt') or die "Cannot open file: $!"; while () { my ($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19,$v20,$v21,$v22,$v23,$v24) = split (/,/); print output "$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19,$v20,$v21,$v22,$v23,$v24\n"; } This reads the input file one line at a time, seperates the variables using the comma as the delimiter, and outputs the variables to a file called out.txt. The challenge is that the file is a structured hierarchy as explained in the original post, I do not know when the lowest level (employee, and this an employees name) will occur in the hierarhcy and I need to get this lowest level value as the first variable in my out.txt file. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Ragged Hierarchy
I have two started the first is my attempt to read the file into an array, the second is processing each variable. I am unsure how to identify the last variable in a variable length line of data. open (input, 'c:\organization.txt') or die "Cannot open file: $!"; @data=; foreach $line(@data){ print $line; } open ('input', 'c:\organization.txt') or die "Cannot open file: $!"; open ('output', '>C:/out.txt') or die "Cannot open file: $!"; while () { my ($v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19,$v20,$v21,$v22,$v23,$v24) = split (/,/); print output "$v1,$v2,$v3,$v4,$v5,$v6,$v7,$v8,$v9,$v10,$v11,$v12,$v13,$v14,$v15,$v16,$v17,$v18,$v19,$v20,$v21,$v22,$v23,$v24\n"; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Crypt SQLite
On Dec 20, 4:49 am, [EMAIL PROTECTED] (Octavian Rasnita) wrote: > From: "Chas. Owens" <[EMAIL PROTECTED]> > > > > > > > On Dec 20, 2007 4:58 AM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > >> From: "Chas. Owens" <[EMAIL PROTECTED]> > > >> > On Dec 19, 2007 5:59 PM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > >> > snip > >> >> Sorry. No idea. I didn't wrote that C# program because I don't know C# > >> >> well > >> >> enough. That's why I was interested in a perl solution, but > >> >> unfortunately > >> >> it > >> >> is not possible in perl. > >> > snip > > >> > It is possible. The person who wrote the C# library probably either > >> > bought the $2,000 license for SEE* or rolled his or her own version of > >> > it. You can buy the license or roll your own version of SEE for Perl > >> > as well. It is quite possible, but, since you can't redistribute the > >> > source code to SEE, there won't be CPAN module for it. Frankly, not > >> > being able to see the source code to System.Data.SQLite.DLL and its > >> > unknown provenence (how can you trust someone you don't know) would > >> > cause me to worry about its level security (did he or she put in a > >> > back door?, did he or she make an error compiling it?, etc.). > > >> > * SQLite Encryption Extension > > >> Yes you are right. That dll might have a backdoor or some bugs in it, as > >> well as any other Windows program that doesn't offer the source code. > >> However, a C# programmer would be able to use an encrypted SQLite > >> database > >> very easy with it, while a perl programmer would need to create its own > >> way > >> of encrypting the database, and this might not be very easy. > > > Actually it is very easy: buy SEE, download DBD::SQLite, swap the SEE > > code with the version of SQLite DBD::SQLite uses, do the Perl make > > dance*. > > It would be still easier to use that dll than to buy a $2000 program... I > guess. :-) > > Octavian- Hide quoted text - > > - Show quoted text - Thanks you guys for your feedback. I found out this morning that my previous SQLite database is still being kept by Windows Vista in its Virtual Store and that's the one that my application was trying to open which of course will have conflict with the encrypted version of System.Data.SQLite.DLL. It was not Vista after all or the new DLL that caused the issue, my bad! I deleted the old database file so that my application can create a new encrypted one and it works fine! Merry Christmas to everyone! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Ragged Hierarchy
On 12/20/07, banker123 <[EMAIL PROTECTED]> wrote: > > I have a text file with a ragged hierarchy as shown below, I would > like to structure the data in a different format (also shown below) > please help. Also the data below is just an example the actual data > file is much larger and the hierarchy has 10 levels the lowest level > "Employee" could be stored anywhere wtihin the 10 levels depeding > upon > the business units structure. I have not used Perl in about 6 months > but > if memory serves me correctly Perl is the perfect tool for the job. > > Original > Company Business Unit1 Employee1 > Company Business Unit1 Business Unit2 Employee2 > > > New > Employee1 Company Business Unit1 > Employee2 Company Business Unit1 Business Unit2 > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ if you only need re-organize company and employee use strict; use warnings; while(){ chomp; my @line = split/\s{5}/; print join (" ", @line[-1, 0, 1.. $#line -1]), "\n"; } __DATA__ Company Business Unit1 Employee1 Company Business Unit1 Business Unit2 Employee2 Company Business Unit1 Business Unit2 Business Unit3 Employee3
Re: Module help
On Dec 20, 2007 2:01 PM, Tom Phoenix <[EMAIL PROTECTED]> wrote: > On 12/20/07, Andy Dixon <[EMAIL PROTECTED]> wrote: > > > sub test($) { > > Subroutine prototypes, like "($)" here, generally cause more harm than > good, alas. Most programmers should avoid using them in most cases. snip You should not use prototypes until you have read and understood everything in FMTEYEWtKaPiP*, but it basically it boils down to this: prototypes are meant modify parsing behavior at compile time not ensure you have the right number or types of arguments. If you want to control the number and type of arguments (what most people try to use prototypes for), Perl provides plenty of tools to do so at runtime: #!/usr/local/ActivePerl-5.10/bin/perl use strict; use warnings; use feature ':5.10'; use Carp; my $n; say "expecting bad number of args:"; eval { $n = n_plus_one(1, 2) }; say $@ ? "got error [EMAIL PROTECTED]" : "\$n is $n\n"; say "expecting bad type"; eval { $n = n_plus_one(2.1) }; say $@ ? "got error [EMAIL PROTECTED]" : "\$n is $n\n"; say "this should work (and return 2):"; eval { $n = n_plus_one(1) }; say $@ ? "got error [EMAIL PROTECTED]" : "\$n is $n\n"; my @a = qw; my @b = my @c = @a; say "expecting bad type:"; eval { $n = are_these_arrays_equal(@a, @b, @c) }; say $@ ? "got error [EMAIL PROTECTED]" : "\$n is $n\n"; say "expecting bad number of args:"; eval { $n = are_these_arrays_equal([EMAIL PROTECTED]) }; say $@ ? "got error [EMAIL PROTECTED]" : "\$n is $n\n"; say "this should work (and return 1)"; eval { $n = are_these_arrays_equal([EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED]) }; say $@ ? "got error [EMAIL PROTECTED]" : "\$n is $n\n"; sub n_plus_one { croak "bad number of arguments, expected 1 got " . @_ unless @_ == 1; my ($n) = @_; croak "the argument should be an integer, you passed [$n]" unless $n =~ /^[1-9][0-9]*$/; return $n + 1; } sub are_these_arrays_equal { croak "bad number of arguments, expected more than one and got " . @_ unless @_ > 1; croak "all arguments should be array references" if grep { ref ne 'ARRAY' } @_; my $one = shift; while (@_) { my $two = shift; return 0 unless @$one ~~ @$two; $one = $two; } return 1; } * http://library.n0i.net/programming/perl/articles/fm_prototypes/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Module help
Thanks everyone who helped - I am new to perl, and after coding with php and various other languages, I have not yet fully grasped some of perl's concepts...! Thanks once again!! -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: variable module
On Dec 20, 2007 2:19 PM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: > Octavian Rasnita wrote: > > and I want to be able to choose the wanted module at runtime snip > Assuming that the path to the directory right above Questionnaire is > included in @INC, this should work: > > require "Questionnaire/$module.pm"; > my $obj = "Questionnaire::$module"->new; snip It is important to note that require does not call the module's import function, so you will need to call it yourself (if it has one). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: variable module
Octavian Rasnita wrote: I have a directory named "Questionnaire" which contains some modules like "Files.pm", "MySQL.pm", and maybe others... and I want to be able to choose the wanted module at runtime, using a code like: my $module = "Files"; require Questionnaire::$module; my $obj = Questionnaire::$module->new(); First please tell me if this is a good practice, I can't see why it shouldn't be. Then please tell me how to do this... if it is possible. Assuming that the path to the directory right above Questionnaire is included in @INC, this should work: require "Questionnaire/$module.pm"; my $obj = "Questionnaire::$module"->new; -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: variable module
On Thursday 20 December 2007 10:38, Octavian Rasnita wrote: > > Hello, Hello, > I have a directory named "Questionnaire" which contains some modules > like "Files.pm", "MySQL.pm", and maybe others... > > and I want to be able to choose the wanted module at runtime, using a > code like: > > my $module = "Files"; > > require Questionnaire::$module; > my $obj = Questionnaire::$module->new(); > > and of course, if I would offer another value for $module, like > "MySQL", the program should use Questionnaire::MySQL instead. > > First please tell me if this is a good practice, or I should better > use > > if ($module eq "Files") { > require Questionnaire::Files; > $obj = Questionnaire::Files->new(); > } > elsif (...) { > ... > } > > Then please tell me how to do this... if it is possible. Look up the "Autoloading" section of perlsub: perldoc perlsub Also: perldoc AutoLoader John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: variable module
On 12/20/07, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > I want to be able to choose the wanted module at runtime At runtime, or at compile time? You have to write your code with some additional care if it has to be compiled before the module is loaded. In any case, see the source for AnyDBM_File for an example of a module that loads one module of many possibilities. The command below should show you the source on your system: perldoc -m AnyDBM_File Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Module help
On Thursday 20 December 2007 10:36, Andy Dixon wrote: > > Hello, Hello, > I have written a small module with a function that returns some text. > > However, when I run it, from a test script, I get: > > Undefined subroutine &external::RETURN called at external.pm line 41. > > The subroutine is thus: Do you have warnings and strict enabled? use warnings; use strict; > sub test($) { Don't use prototypes: http://library.n0i.net/programming/perl/articles/fm_prototypes/ > my $data = @_; An array in scalar context will return the number of elements of that array so you need to either use list context: my ( $data ) = @_; Or assign a scalar in scalar context: my $data = $_[ 0 ]; Or: my $data = shift; > $data =~ s/cheese/ham/g; $data will not be modified as it only contains numbers. You may want to anchor your pattern. Do you want to change the word 'cheesecloth' to 'hamcloth'? > RETURN ($data); Perl is case sensitive: return $data; > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: variable module
On Dec 20, 6:38 pm, [EMAIL PROTECTED] (Octavian Rasnita) wrote: > I have a directory named "Questionnaire" which contains some modules like > "Files.pm", "MySQL.pm", and maybe others... > > and I want to be able to choose the wanted module at runtime, using a code > like: > > my $module = "Files"; > > require Questionnaire::$module; > my $obj = Questionnaire::$module->new(); eval "require Questionnaire::$module; 1" or die $@; my $obj = "Questionnaire::$module"->new(); See also UNIVERSAL::require > First please tell me if this is a good practice, or I should better use > > if ($module eq "Files") { > require Questionnaire::Files; > $obj = Questionnaire::Files->new();} That is a bit of a religious issue. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Module help
On 12/20/07, Andy Dixon <[EMAIL PROTECTED]> wrote: > sub test($) { Subroutine prototypes, like "($)" here, generally cause more harm than good, alas. Most programmers should avoid using them in most cases. > my $data = @_; You're using the "name" of the array in scalar context; this gives the number of elements. From the way you're using $data, you probably wanted to use list context to get the actual element: my($data) = @_; > RETURN ($data); Perl is a case-sensitive language, so the return operator must not be capitalized. If you've seen RETURN like that in someone else's code, that's a subroutine call; presumably one that does some special kind of return operation other than the standard one. Hope this helps! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: Module help
> -Original Message- > From: Andy Dixon [mailto:[EMAIL PROTECTED] > Sent: Thursday, December 20, 2007 10:37 > To: Perl beginners > Subject: Module help > > Hello, > > I have written a small module with a function that returns some text. > > However, when I run it, from a test script, I get: > > Undefined subroutine &external::RETURN called at external.pm line 41. > > The subroutine is thus: > > sub test($) { You are using I believe pro-typing and I believe you are better off not using. > > my $data = @_; > > $data =~ s/cheese/ham/g; > > RETURN ($data); it is return not RETURN Wags ;) > > } > > > I think I may have missed something.. Any help would be wonderful! > > Thanks! > > Andy > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > http://learn.perl.org/ > > > ** This message contains information that is confidential and proprietary to FedEx Freight or its affiliates. It is intended only for the recipient named and for the express purpose(s) described therein. Any other use is prohibited. ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
variable module
Hello, I have a directory named "Questionnaire" which contains some modules like "Files.pm", "MySQL.pm", and maybe others... and I want to be able to choose the wanted module at runtime, using a code like: my $module = "Files"; require Questionnaire::$module; my $obj = Questionnaire::$module->new(); and of course, if I would offer another value for $module, like "MySQL", the program should use Questionnaire::MySQL instead. First please tell me if this is a good practice, or I should better use if ($module eq "Files") { require Questionnaire::Files; $obj = Questionnaire::Files->new(); } elsif (...) { ... } Then please tell me how to do this... if it is possible. Thank you. Octavian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Module help
Hello, I have written a small module with a function that returns some text. However, when I run it, from a test script, I get: Undefined subroutine &external::RETURN called at external.pm line 41. The subroutine is thus: sub test($) { my $data = @_; $data =~ s/cheese/ham/g; RETURN ($data); } I think I may have missed something.. Any help would be wonderful! Thanks! Andy -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Ragged Hierarchy
On Thursday 20 December 2007 07:49, banker123 wrote: > > I have a text file with a ragged hierarchy as shown below, I would > like to structure the data in a different format (also shown below) > please help. Also the data below is just an example the actual data > file is much larger and the hierarchy has 10 levels the lowest level > "Employee" could be stored anywhere wtihin the 10 levels depeding > upon the business units structure. I have not used Perl in about 6 > months but if memory serves me correctly Perl is the perfect tool for > the job. > > Original > Company Business Unit1 Employee1 > Company Business Unit1 Business Unit2 Employee2 > > > New > Employee1 Company Business Unit1 > Employee2 Company Business Unit1 Business Unit2 $ echo "Company Business Unit1 Employee1 Company Business Unit1 Business Unit2 Employee2" |\ perl -lne' my ( $co, @data ) = split /\s{2,}/; my ( $bu, $empl ) = splice @data, -2; printf q[%-14s%-12s] . ( q[%-19s] x @data ) . qq[%s\n], $empl, $co, @data, $bu; ' Employee1 Company Business Unit1 Employee2 Company Business Unit1 Business Unit2 John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Persistent Data with HTTP, Apache and Perl
On 12/20/07, Nigel Peck <[EMAIL PROTECTED]> wrote: > I'm looking for some recommendations of ways to have http sessions using > Apache and Perl. Then you probably want a forum about http sessions, Apache, and Perl. Even if you're not using mod_perl (but you probably are), permit me to recommend the mod_perl Users mailing list: http://perl.apache.org/maillist/modperl.html Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Ragged Hierarchy
On 12/20/07, banker123 <[EMAIL PROTECTED]> wrote: > I have a text file with a ragged hierarchy as shown below, I would > like to structure the data in a different format (also shown below) > please help. It sounds as if you want to read a text file, build a Perl data structure in memory, perhaps modify parts of the structure, then write the data out to another file. Perl is good at this sort of thing. How far have you gotten on your own? Do you know how to read your data into a Perl data structure, for example? If you can post the code that you've written, someone may have some suggestions for how to improve it. Cheers! --Tom Phoenix Stonehenge Perl Training -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Ragged Hierarchy
I have a text file with a ragged hierarchy as shown below, I would like to structure the data in a different format (also shown below) please help. Also the data below is just an example the actual data file is much larger and the hierarchy has 10 levels the lowest level "Employee" could be stored anywhere wtihin the 10 levels depeding upon the business units structure. I have not used Perl in about 6 months but if memory serves me correctly Perl is the perfect tool for the job. Original Company Business Unit1 Employee1 Company Business Unit1 Business Unit2 Employee2 New Employee1 Company Business Unit1 Employee2 Company Business Unit1 Business Unit2 -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Persistent Data with HTTP, Apache and Perl
Hi all, I'm looking for some recommendations of ways to have http sessions using Apache and Perl. I have (will have) a shopping application that needs to work across user's visits to static html pages, so passing a session id in the page is not viable. I don't want to rely on cookies. How do http sessions work? What's the best way to use them with Apache/Perl? Do all current browsers pass the http header with the session id back and forth? Cheers, Nigel -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reg. ex.
Chas. Owens wrote: A regex in scalar context returns a 1 if it matches and a 0 if it doesn't. Not quite. A failed regex match returns the null string '', not a zero value. It is of course still false for boolean tests. Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Crypt SQLite
From: "Chas. Owens" <[EMAIL PROTECTED]> On Dec 20, 2007 4:58 AM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: From: "Chas. Owens" <[EMAIL PROTECTED]> > On Dec 19, 2007 5:59 PM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > snip >> Sorry. No idea. I didn't wrote that C# program because I don't know C# >> well >> enough. That's why I was interested in a perl solution, but >> unfortunately >> it >> is not possible in perl. > snip > > It is possible. The person who wrote the C# library probably either > bought the $2,000 license for SEE* or rolled his or her own version of > it. You can buy the license or roll your own version of SEE for Perl > as well. It is quite possible, but, since you can't redistribute the > source code to SEE, there won't be CPAN module for it. Frankly, not > being able to see the source code to System.Data.SQLite.DLL and its > unknown provenence (how can you trust someone you don't know) would > cause me to worry about its level security (did he or she put in a > back door?, did he or she make an error compiling it?, etc.). > > * SQLite Encryption Extension Yes you are right. That dll might have a backdoor or some bugs in it, as well as any other Windows program that doesn't offer the source code. However, a C# programmer would be able to use an encrypted SQLite database very easy with it, while a perl programmer would need to create its own way of encrypting the database, and this might not be very easy. Actually it is very easy: buy SEE, download DBD::SQLite, swap the SEE code with the version of SQLite DBD::SQLite uses, do the Perl make dance*. It would be still easier to use that dll than to buy a $2000 program... I guess. :-) Octavian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reg. ex.
On Dec 20, 2007 5:27 AM, Sayed, Irfan (Irfan) <[EMAIL PROTECTED]> wrote: snip > $ts = ($test =~ m{(.+)\@/}); snip > but again the same output. I am not getting output as "test" snip That is because you are still putting the regex in scalar context instead of list context. A regex in scalar context returns a 1 if it matches and a 0 if it doesn't. A regex in list context returns the captures. Just add a set of parenthesis around the target variable to force list context. While you are at it get rid of the useless parenthesis you are using around $test =~ m{(.+)\@/}. ($ts) = $test =~ m{(.+)\@/}; Given what your code looks like I am also guessing you have not used the warnings and strict pragmas, I cannot stress how important they are. Failure to use them will give you no end of headache (as you ca already see from the @$ issue). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
RE: reg. ex.
Thanks Jeff. As per your suggestion I did following. $test="test@/vobs/pvob_aic"; $ts = ($test =~ m{(.+)\@/}); print "$ts\n"; but again the same output. I am not getting output as "test" Please guide. Regards Irfan. -Original Message- From: Jeff Pang [mailto:[EMAIL PROTECTED] Sent: Thursday, December 20, 2007 2:31 PM To: Sayed, Irfan (Irfan); beginners @ perl. org Subject: Re: reg. ex. -Original Message- >From: "Sayed, Irfan (Irfan)" <[EMAIL PROTECTED]> >Sent: Dec 20, 2007 4:53 PM >To: "beginners @ perl. org" >Subject: reg. ex. > >Hi All, > >I have one string like this "test@/vobs/pvob_aic"; > >Now I want only "test" from this string, so I wrote reg. ex. like this > >$test="test@/vobs/pvob_aic"; >$ts = ($test =~ m{(.+)@$}); '$' means end of a line, you shouldn't specify a $ here. > >But I am getting output as 1 not a string "test" > >can some body please give me exact reg.ex. to achieve this > $ perl -Mstrict -le '$_="test@/vobs/pvob_aic"; print $1 if /(.+)\@/' test -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: SNMP
On Dec 20, 2007 3:17 AM, Anirban Adhikary <[EMAIL PROTECTED]> wrote: > Dear List > > I want to write a system monitoring script using SNMP protocol. So for that > reason I need a sample script in PERL using NET::SNMP module of SNMP agent > as well as SNMP manager. Regarding this if I get any help from you people I > will be highly obliged. snip three things: 1. It is Perl if you are talking about the language or perl if you are talking about the interpreter. It is never* PERL. 2. There is no module named NET::SNMP, it is Net::SNMP. 3. A quick Google search** will net you quite a few examples of varying quality. * well, I guess if you are on a really old system that only does uppercase it could be PERL, but that is very rare. ** http://www.google.com/search?q=perl+snmp+example -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Crypt SQLite
On Dec 20, 2007 4:58 AM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > From: "Chas. Owens" <[EMAIL PROTECTED]> > > > > On Dec 19, 2007 5:59 PM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: > > snip > >> Sorry. No idea. I didn't wrote that C# program because I don't know C# > >> well > >> enough. That's why I was interested in a perl solution, but unfortunately > >> it > >> is not possible in perl. > > snip > > > > It is possible. The person who wrote the C# library probably either > > bought the $2,000 license for SEE* or rolled his or her own version of > > it. You can buy the license or roll your own version of SEE for Perl > > as well. It is quite possible, but, since you can't redistribute the > > source code to SEE, there won't be CPAN module for it. Frankly, not > > being able to see the source code to System.Data.SQLite.DLL and its > > unknown provenence (how can you trust someone you don't know) would > > cause me to worry about its level security (did he or she put in a > > back door?, did he or she make an error compiling it?, etc.). > > > > * SQLite Encryption Extension > > Yes you are right. That dll might have a backdoor or some bugs in it, as > well as any other Windows program that doesn't offer the source code. > However, a C# programmer would be able to use an encrypted SQLite database > very easy with it, while a perl programmer would need to create its own way > of encrypting the database, and this might not be very easy. Actually it is very easy: buy SEE, download DBD::SQLite, swap the SEE code with the version of SQLite DBD::SQLite uses, do the Perl make dance*. * which looks like this perl Makefile.PL make make test sudo make install -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Crypt SQLite
From: "Chas. Owens" <[EMAIL PROTECTED]> On Dec 19, 2007 5:59 PM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: snip Sorry. No idea. I didn't wrote that C# program because I don't know C# well enough. That's why I was interested in a perl solution, but unfortunately it is not possible in perl. snip It is possible. The person who wrote the C# library probably either bought the $2,000 license for SEE* or rolled his or her own version of it. You can buy the license or roll your own version of SEE for Perl as well. It is quite possible, but, since you can't redistribute the source code to SEE, there won't be CPAN module for it. Frankly, not being able to see the source code to System.Data.SQLite.DLL and its unknown provenence (how can you trust someone you don't know) would cause me to worry about its level security (did he or she put in a back door?, did he or she make an error compiling it?, etc.). * SQLite Encryption Extension Yes you are right. That dll might have a backdoor or some bugs in it, as well as any other Windows program that doesn't offer the source code. However, a C# programmer would be able to use an encrypted SQLite database very easy with it, while a perl programmer would need to create its own way of encrypting the database, and this might not be very easy. Octavian -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reg. ex.
On Dec 20, 2007 4:37 AM, Gunnar Hjalmarsson <[EMAIL PROTECTED]> wrote: snip > >> $ts = ($test =~ m{(.+)@$}); snip > > '$' means end of a line, > > Obviously not in this case, since the regex returns 1 in scalar context > (i.e. it matches). snip It is returning 1 because it is in scalar context, @$ is undefined (making the regex /(.+)/), and there is at least one character in $test. With the proper quoting of @ the $ will in fact cause problems for the OP. Here is an interesting fact: the strict pragma will not catch @$ even though it is not a variable defined in perldoc perlvar and was not declared. This is why the strict pragma should always be paired with the warnings pragma (and vice versa). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Crypt SQLite
On Dec 19, 2007 5:59 PM, Octavian Rasnita <[EMAIL PROTECTED]> wrote: snip > Sorry. No idea. I didn't wrote that C# program because I don't know C# well > enough. That's why I was interested in a perl solution, but unfortunately it > is not possible in perl. snip It is possible. The person who wrote the C# library probably either bought the $2,000 license for SEE* or rolled his or her own version of it. You can buy the license or roll your own version of SEE for Perl as well. It is quite possible, but, since you can't redistribute the source code to SEE, there won't be CPAN module for it. Frankly, not being able to see the source code to System.Data.SQLite.DLL and its unknown provenence (how can you trust someone you don't know) would cause me to worry about its level security (did he or she put in a back door?, did he or she make an error compiling it?, etc.). * SQLite Encryption Extension -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reg. ex.
Jeff Pang wrote: Sayed, Irfan (Irfan) wrote: Now I want only "test" from this string, so I wrote reg. ex. like this Missing: use strict; use warnings; $test="test@/vobs/pvob_aic"; $ts = ($test =~ m{(.+)@$}); print "$ts\n"; But I am getting output as 1 not a string "test" '$' means end of a line, Obviously not in this case, since the regex returns 1 in scalar context (i.e. it matches). you shouldn't specify a $ here. Agreed. ;-) -- Gunnar Hjalmarsson Email: http://www.gunnar.cc/cgi-bin/contact.pl -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: Hi... Help regarding chdir
On Dec 19, 2007 2:05 PM, Tom Phoenix <[EMAIL PROTECTED]> wrote: > On 12/19/07, Chas. Owens <[EMAIL PROTECTED]> wrote: > > > On Dec 19, 2007 2:29 AM, Ravindra Ugaji <[EMAIL PROTECTED]> wrote: > > > > chdir ( '/opt/application') || die ("Can't change directory: $!\n"); > > > tried this also > > > chdir "/opt/application" || die "Can't change directory: $!\n"; > > > In addition to what others have already said, never do the second*. > > The || operator has a higher precedence than function calls, so > > > > func "string" || die "oops"; > > > > is really saying > > > > func("string" || die("oops")); > > > > Since "string" is truthy, the die will never occur. > > You have the right idea about functions in general; but chdir() is a > "named unary operator", so it has higher precedence than the || > operator: > > chdir "/any/wrong/path" || die "This will indeed die: $!"; > > That means that the OP's code isn't so wrong as it may seem, even > though there's surely a better way to write it. snip That is the reason I used func instead of chdir. The "don't use || in that way, use or instead" is more of a general warning not to use the construct (because it will bite you). -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: testing for a file type
On Dec 19, 2007 7:01 PM, Jenda Krynicky <[EMAIL PROTECTED]> wrote: snip > I did not install it yet so I can't check but I think you have it > wrong. According to the docs you point to > >@ARGV ~~ /\.mdb\z/ > > is equivalent to > >grep /\.mdb\z/, @ARGV > > which is true whenever at least one item in the array matches the > regexp. snip Yeah, I jumped the gun. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reg. ex.
On Dec 20, 2007 3:53 AM, Sayed, Irfan (Irfan) <[EMAIL PROTECTED]> wrote: > Hi All, > > I have one string like this "test@/vobs/pvob_aic"; > > Now I want only "test" from this string, so I wrote reg. ex. like this > > $test="test@/vobs/pvob_aic"; > $ts = ($test =~ m{(.+)@$}); > print "$ts\n"; > > But I am getting output as 1 not a string "test" snip This is why you need to use the warnings pragma (and the strict pragma). If you had you would have seen this warning: Possible unintended interpolation of @$ in string at f.pl line 7. You have three: 1. @$ in the regex is being treated like the array @$. 2. You are using the regex in scalar context* instead of list context**. 3. The $ metacharacter will cause the pattern not to match (because the @ symbol is not at the end of the line). You can fix 1. with by escaping @. You can fix 2. by using parenthesis around the variables you are trying to assign to. You can fix 3. by either extending the regex or removing the $. my ($ts) = $test =~ /(.+)[EMAIL PROTECTED]/; or my ($ts) = $test =~ /(.+)\@/; * in list context, a regex returns the captures ** in scalar context, a regex returns a boolean value that says whether or not it matched -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: reg. ex.
-Original Message- >From: "Sayed, Irfan (Irfan)" <[EMAIL PROTECTED]> >Sent: Dec 20, 2007 4:53 PM >To: "beginners @ perl. org" >Subject: reg. ex. > >Hi All, > >I have one string like this "test@/vobs/pvob_aic"; > >Now I want only "test" from this string, so I wrote reg. ex. like this > >$test="test@/vobs/pvob_aic"; >$ts = ($test =~ m{(.+)@$}); '$' means end of a line, you shouldn't specify a $ here. > >But I am getting output as 1 not a string "test" > >can some body please give me exact reg.ex. to achieve this > $ perl -Mstrict -le '$_="test@/vobs/pvob_aic"; print $1 if /(.+)\@/' test -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
Re: regexp for two quotes
Rob Dixon schreef: > Dr.Ruud wrote: >> Jay Savage schreef: >>> Corin Lawson wrote: Can you not simply count the number of quotes mod 2? >>> >>> No, you can't just count the number of quotes. An even number of >>> quotes doesn't mean they're all double quotes. Consider something >>> like q|a'b'c''d'e'f|. >> >> I haven't read anywhere yet that the quotes should be touching. > > Scooter is leaving us all speculating about his true requirement, but > I read his OP as meaning all single quotes should occur in (touching) > pairs, and any isolated single quote in the string is an error. > Whether or not groups of three or more are allowed is another matter. Not another matter, just another interpretation. A "single quote" is what is left from q{'''} when you dealt with the first "two quotes". Also see how Jay made the switch from "two quotes" to "double quotes". I like these "you are what you read" happenings. Let's wait for scooter. -- Affijn, Ruud "Gewoon is een tijger." -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/
reg. ex.
Hi All, I have one string like this "test@/vobs/pvob_aic"; Now I want only "test" from this string, so I wrote reg. ex. like this $test="test@/vobs/pvob_aic"; $ts = ($test =~ m{(.+)@$}); print "$ts\n"; But I am getting output as 1 not a string "test" can some body please give me exact reg.ex. to achieve this Please guide Regards Irfan.
SNMP
Dear List I want to write a system monitoring script using SNMP protocol. So for that reason I need a sample script in PERL using NET::SNMP module of SNMP agent as well as SNMP manager. Regarding this if I get any help from you people I will be highly obliged. Thanks&Regards in advance Anirban Adhikary.