Re: use string in "use"

2020-12-15 Thread Chas. Owens
The use function happens at compile time and must take a bareword, but it is functionally equivalent to BEGIN { require Module; Module->import( LIST ); } And the require function allows you to pass a string, but be aware there are lots of differences in behavior when passing a string

Re: use string in "use"

2020-12-14 Thread Jim Gibson
d all goes well. However, > I want to know if / how I can use a string variable in the 'use' clause. > > In PHP I have a simple system of turning on/off debugging and version > control. Any file *1.html is development version. I then have > > $DEBUG=(preg_match('/1.htm

use string in "use"

2020-12-14 Thread Gary Stainburn
I've written my first re-usable modules in Perl, and all goes well. However, I want to know if / how I can use a string variable in the 'use' clause. In PHP I have a simple system of turning on/off debugging and version control.  Any file *1.html is development version.  I then have $DEBUG

Re: Is there a definition of what is a string in perl, and what is it?

2019-05-21 Thread Uri Guttman
to some improvements and have shown that, while somewhat inconclusive, there is no other way to do it in perl because the data type I would need does not exist in perl. That will have to suffice. perl doesn't have data typing as such.  a scalar can hold an integer, a float or a string. the string

Re: can I use some kind of binary string?

2019-05-18 Thread Shlomi Fish
nt to use something like > >>>> > >>>> > >>>> my $binary_data = `curl -k "https://www.example.com/some.jpg"`; > >>>> > >>> > >>> Perl distinguishes between 8-bit/binary strings and unicode ones. See

Re: can I use some kind of binary string?

2019-05-18 Thread hwilmer
ry strings and unicode ones. See https://perldoc.perl.org/perlunitut.html . What kind of string do I get when using backticks like in the above example? > [...] Perhaps use open "-|" with an encoding - see https://perldoc.perl.org/functions/binmode.html . I didn't know I cou

Re: Is there a definition of what is a string in perl, and what is it?

2019-05-17 Thread Uri Guttman
lification, strings are very complicated things.  You might imagine a "binary string" as a number of consecutive bytes, with "consecutive" meaning that one byte comes after the other, and the order in which they come is relevant.  You could describe a string like that, bu

Re: Is there a definition of what is a string in perl, and what is it?

2019-05-17 Thread hwilmer
--- and never in lines unless they get in the way and force me to consider them. A string is not a single value. And when you keep reading until you get to the "Discussion" section, you would have to conclude that there are no characters in perl, and I'm getting back to basically th

Re: Is there a definition of what is a string in perl, and what is it?

2019-05-16 Thread Andrew Solomon
or example, noting that print 4; and print 0b100; both output 4, would you refer to 0b100 as a binary string? On Thu, May 16, 2019 at 5:51 PM hwilmer wrote: > > Hi, > > since I'm trying to use "binary strings", the question comes up if there > is a definition of

Re: can I use some kind of binary string?

2019-05-16 Thread Shlomi Fish
So I would want to use something like > >> > >> > >> my $binary_data = `curl -k "https://www.example.com/some.jpg"`; > >> > > > > Perl distinguishes between 8-bit/binary strings and unicode ones. See > > https://perldoc.perl.org/perlun

Is there a definition of what is a string in perl, and what is it?

2019-05-16 Thread hwilmer
Hi, since I'm trying to use "binary strings", the question comes up if there is a definition of what is a string in perl, and what is it? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: can I use some kind of binary string?

2019-05-16 Thread hwilmer
nitut.html . What kind of string do I get when using backticks like in the above example? One that perl considers as a text string I could use stuff like uc or lc on, or as a binary string I could use pack or unpack on? Variables are without types, so there is no way to tell. If I was using curl

Re: can I use some kind of binary string?

2019-05-11 Thread Shlomi Fish
DBI in > such a way that the image can be restored as it was. > > Will string conversions or something prevent this from working? > > What is the usual way to do this? It is certainly not ideal to have no > check on the amount of data that might be retrieved from t

can I use some kind of binary string?

2019-05-10 Thread hwilmer
something like my $binary_data = `curl -k "https://www.example.com/some.jpg"`; The image then needs to be inserted into a LONGBLOB field via DBI in such a way that the image can be restored as it was. Will string conversions or something prevent this from working? What is the usual

Re: Converting string to float

2017-03-02 Thread Gil Magno
On Thu, Mar 02, 2017 at 04:50:32PM +, mailing lists via beginners wrote: > > > just to clarify, the real purpose of the script is output the hash to a json > object, so the json output for the script: So you have to "numify" your number: https://metacpan.org/pod/JSON::PP#PERL-%3E-JSON

Re: Converting string to float

2017-03-02 Thread Илья Рассадин
See docs https://metacpan.org/pod/JSON::PP#simple-scalars You do print Dumper on hash, it stringifies all hash values, so you see such an obscure result for encode_json. If don't dump $hash before encode json you get what you want - work_hours_to_float_try2 is json valid number

Re: Converting string to float

2017-03-02 Thread Shawn H Corey
meric values) and not floats. So the real question is how to > output float numbers in this case. Perl automatically converts from number to string and back. When I try it, I get the following, which seems to be correct. $VAR1 = { 'work_hours' => '4.1', 'work_hours_

Re: Converting string to float

2017-03-02 Thread mailing lists via beginners
just to clarify, the real purpose of the script is output the hash to a json object, so the json output for the script: #!/usr/bin/perl use strict; use warnings; use Data::Dumper; use JSON::PP; my ($input_string, %job_task); sub sanitize_data{ my $data = shift; $data->{'work_hours'} =

Converting string to float

2017-03-02 Thread mailing lists via beginners
Helo all, what I am trying to do is convert a value contained whitin a hash from string to float, but I fail to find the error, this is that I have tried: $ cat test.pl #!/usr/bin/perl use strict; use warnings; use Data::Dumper; my ($input_string, %job_task); sub sanitize_data{ my $data

Re: suggestion for print format string based on configuration

2017-01-03 Thread Luca Ferrari
On Wed, Jan 4, 2017 at 12:22 AM, Chris Fedde wrote: > my ($condition, @fields) = parse_data($source_item); > print sprintf $formats[ $condition ], @fields; > > Or something. Well, I've simplified the example and effectively, in my code, the formats is an hash instrumented

Re: suggestion for print format string based on configuration

2017-01-03 Thread Luca Ferrari
On Tue, Jan 3, 2017 at 5:58 PM, Shlomi Fish wrote: > Perhaps try looking at this page about generating text in Perl - > http://perl-begin.org/uses/text-generation/ (note that Perl-Begin is a site > which I maintain). This page on my personal website, which is not >

Re: suggestion for print format string based on configuration

2017-01-03 Thread Chris Fedde
: my ($condition, @fields) = parse_data($source_item); print sprintf $formats[ $condition ], @fields; Or something. if this works then $condition could be some string from the $source_item. Then @formats could be %formats and $condition is the key and the printf format is the value. Here

Re: suggestion for print format string based on configuration

2017-01-03 Thread Shlomi Fish
t; for something more elegant. > What I do is something like the following: > > print sprintf $formats[ $condition ], @fields; > > where $condition is the condition used to select a sprintf format > string out of an array (@formats) that contains something like: > > my @fo

suggestion for print format string based on configuration

2017-01-03 Thread Luca Ferrari
; where $condition is the condition used to select a sprintf format string out of an array (@formats) that contains something like: my @formats = ( qw( %09d %-1s %03d ... ) , qw(%-4s %1s %09d %1s %-150s %-4s %011d) , ... ); Now, while this approach is working really fine, it is a little hard

Re: Remove Newlines from String

2016-09-09 Thread Chas. Owens
On Tue, Sep 6, 2016 at 3:24 PM Shawn H Corey wrote: > > #Change the value to the maximum you want > > my %HEXCODES = map{$_ => sprintf("%03X", $_)} (0..128); > > my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 ); > Just your friendly reminder that

Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
On Tue, 6 Sep 2016 22:08:40 +0200 David Emanuel da Costa Santiago wrote: > > > Thanks :-) > > A little bug: > > > my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 ); > my %HexCodes = map { chr($_) => sprintf '%02X', $_ } ( 0 .. 128 ); > > > > Oops. :)

Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
On Tue, 6 Sep 2016 17:01:52 -0400 Uri Guttman wrote: > On 09/06/2016 04:42 PM, X Dungeness wrote: > > It's kinda hard to see but I included the /x switch because > > I inserted blanks on the pattern as well as the replacement > > side. Without /x, the match will fail. > > >

Re: Remove Newlines from String

2016-09-06 Thread Uri Guttman
On 09/06/2016 04:42 PM, X Dungeness wrote: It's kinda hard to see but I included the /x switch because I inserted blanks on the pattern as well as the replacement side. Without /x, the match will fail. $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; ^

Re: Remove Newlines from String

2016-09-06 Thread X Dungeness
It's kinda hard to see but I included the /x switch because I inserted blanks on the pattern as well as the replacement side. Without /x, the match will fail. $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; ^ ^ On Tue, Sep 6, 2016 at 1:06 PM,

Re: Remove Newlines from String

2016-09-06 Thread David Emanuel da Costa Santiago
Thanks :-) A little bug: > my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 ); my %HexCodes = map { chr($_) => sprintf '%02X', $_ } ( 0 .. 128 ); -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org

Re: Remove Newlines from String

2016-09-06 Thread Uri Guttman
On 09/06/2016 03:59 PM, X Dungeness wrote: $str = "ab\rcd\nef\ngh\fij"; $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; > ab(0XD)cd(0XA)ef(0XA)gh(0XC)ij that is a nice use of /e (don't think you need /x when you already have /e as code can handle blanks. but the #

Re: Remove Newlines from String

2016-09-06 Thread X Dungeness
$str = "ab\rcd\nef\ngh\fij"; $str =~ s{ ([^[:print:]]) }{ sprintf( "(%#2X)", ord $1) }gex; > ab(0XD)cd(0XA)ef(0XA)gh(0XC)ij On Tue, Sep 6, 2016 at 9:11 AM, Matt <matt.mailingli...@gmail.com> wrote: > I am receiving log entries as a string

Re: Remove Newlines from String

2016-09-06 Thread Shawn H Corey
EXCODES = map{$_ => sprintf("%03X", $_)} (0..128); my %HexCodes = map { ord($_) => sprintf '%02X', $_ } ( 0 .. 128 ); > > my $s="This is my string! \r\n the end"; > > say "String before: $s"; > > #Change the character class you want >

Re: Remove Newlines from String

2016-09-06 Thread David Emanuel da Costa Santiago
Hi! You can use "chomp" to remove the $/ from the end of the line. If you want to replace all non printable characters you can do something like: ### START #Change the value to the maximum you want my %HEXCODES = map{$_ => sprintf("%03X", $_)} (0..128); my $s=&

Re: Remove Newlines from String

2016-09-06 Thread Kenneth Wolcott
On Tue, Sep 6, 2016 at 9:11 AM, Matt <matt.mailingli...@gmail.com> wrote: > I am receiving log entries as a string and then writing them to a file > with the date tacked on beginning. Problem is that sometimes the > string I receive contains \n and it makes parsing the file w

Remove Newlines from String

2016-09-06 Thread Matt
I am receiving log entries as a string and then writing them to a file with the date tacked on beginning. Problem is that sometimes the string I receive contains \n and it makes parsing the file with grep more difficult. Looking for a simple way to replace all \n in the string with text

Re: Are there (non-obvious) differences in string quoting methods?

2016-04-07 Thread Shawn H Corey
downsides of using this method more > > generally (other than double-quotes being two characters shorter)? > > For example, is it "faster" for Perl to parse a double-quoted > > string or does the compiler optimise this out so the methods are > > fundamentally equival

Re: Are there (non-obvious) differences in string quoting methods?

2016-04-06 Thread Uri Guttman
ng two characters shorter)? For example, is it "faster" for Perl to parse a double-quoted string or does the compiler optimise this out so the methods are fundamentally equivalent? In that regards you can get a reasonable look at how perl interprets your string with B::Deparse, partly bec

Re: Are there (non-obvious) differences in string quoting methods?

2016-04-06 Thread Kent Fredric
rter)? For example, is it "faster" > for Perl to parse a double-quoted string or does the compiler optimise > this out so the methods are fundamentally equivalent? In that regards you can get a reasonable look at how perl interprets your string with B::Deparse, partly because the deparse rever

Re: Are there (non-obvious) differences in string quoting methods?

2016-04-06 Thread Paul Johnson
On Wed, Apr 06, 2016 at 08:20:24PM +0100, Jonathon Fernyhough wrote: > Hi, > > I'm working my way through Learning Perl (6th) and Modern Perl (4th) and > was wondering whether there are any (non-obvious) drawbacks to the > different string quoting methods. > > First up,

Re: Are there (non-obvious) differences in string quoting methods?

2016-04-06 Thread Shawn H Corey
On Wed, 6 Apr 2016 15:29:26 -0400 Uri Guttman <u...@stemsystems.com> wrote: > my rule is for the reader and not the computer. i try to use '' when > i know there is no interpolation and "" when there is. i am telling > the reader to either not look or to look inside th

Re: Are there (non-obvious) differences in string quoting methods?

2016-04-06 Thread Uri Guttman
On 04/06/2016 03:20 PM, Jonathon Fernyhough wrote: Hi, I'm working my way through Learning Perl (6th) and Modern Perl (4th) and was wondering whether there are any (non-obvious) drawbacks to the different string quoting methods. First up, double-quoted strings. The "usual method"

Are there (non-obvious) differences in string quoting methods?

2016-04-06 Thread Jonathon Fernyhough
Hi, I'm working my way through Learning Perl (6th) and Modern Perl (4th) and was wondering whether there are any (non-obvious) drawbacks to the different string quoting methods. First up, double-quoted strings. The "usual method" of double-quoting has an alternative of qq{Fo

Re: Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-09 Thread Brock Wilcox
rt { $a <=> $b } @a; say join("\n",@b)' 12 hi 37 b 123 c 187 a You can scope this if you like: my @result; { no warnings 'numeric'; @result = sort { $a <=> $b } @source; } You could also force the string to a number using a thing fr

Re: Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-08 Thread Shawn H Corey
On Tue, 8 Mar 2016 13:29:40 -0800 Kenneth Wolcott <kennethwolc...@gmail.com> wrote: > How do I call the built-in Perl sort function on an array of strings > where the string is composed of one or more digits, followed by a tab > which is followed by a string and I want the resul

Re: Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-08 Thread Andrew Solomon
Hi Ken I just wrote this https://gist.github.com/andrewsolomon/65b795be10da569f878d and then realised it could be simpler because you'll have a tab between the number and string. Does this give you enough to work off? Andrew On Tue, Mar 8, 2016 at 9:29 PM, Kenneth Wolcott <kennethw

Perl sort for reverse numeric if numbers and text are in a string, numbers first

2016-03-08 Thread Kenneth Wolcott
Hi; How do I call the built-in Perl sort function on an array of strings where the string is composed of one or more digits, followed by a tab which is followed by a string and I want the results to be sorted in reverse numeric order? I looked at http://perldoc.perl.org/functions/sort.html

Re: How to interpolate a hash in a string

2015-11-04 Thread David Emanuel da Costa Santiago
mail.com> wrote: > Re-sending with CC to OP since it didn't make the group. > > On 11/3/2015 14:03, David Emanuel da Costa Santiago wrote: > > -BEGIN PGP SIGNED MESSAGE- > > Hash: SHA256 > > > > > > Hello all. > > > > I'm trying to interpo

How to interpolate a hash in a string

2015-11-03 Thread David Emanuel da Costa Santiago
-BEGIN PGP SIGNED MESSAGE- Hash: SHA256 Hello all. I'm trying to interpolate a hash value in a string but i got stuck. I already tried with eval, without any success... I have two conf files in the form conf file 1: option=value option2=value2 conf file 2: property=propertyValue

Re: How to interpolate a hash in a string

2015-11-03 Thread Jim Gibson
> On Nov 3, 2015, at 2:03 PM, David Emanuel da Costa Santiago > <deman...@gmail.com> wrote: > > -BEGIN PGP SIGNED MESSAGE- > Hash: SHA256 > > > Hello all. > > I'm trying to interpolate a hash value in a string but i got stuck. > I already tried

Re: parsing string output that isn't CSV, but similar; what module would parse these kind of key-value pairs?

2014-12-19 Thread Mike Raynham
of split? Perhaps something like: $example_string =~ m|'($1)'|; $shared_folder = $1; Is there a better way to do this? What kind of string format is this called? Thanks, Ken Wolcott Rather than attempting to parse the human-readable output from VBoxManage, have you instead tried

parsing string output that isn't CSV, but similar; what module would parse these kind of key-value pairs?

2014-12-16 Thread Kenneth Wolcott
)'|; $shared_folder = $1; Is there a better way to do this? What kind of string format is this called? Thanks, Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: parsing string output that isn't CSV, but similar; what module would parse these kind of key-value pairs?

2014-12-16 Thread Tiago Hori
this? What kind of string format is this called? Thanks, Ken Wolcott -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/ -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional

Re: parsing string output that isn't CSV, but similar; what module would parse these kind of key-value pairs?

2014-12-16 Thread Kenneth Wolcott
: $example_string =~ m|'($1)'|; $shared_folder = $1; Is there a better way to do this? What kind of string format is this called? Thanks, Ken Wolcott Well, I had to look at http://perldoc.perl.org/perlrequick.html#Extracting-matches to find out how much I had forgotten about extracting matches from

Re: parsing string output that isn't CSV, but similar; what module would parse these kind of key-value pairs?

2014-12-16 Thread Brandon McCaig
On Tue, Dec 16, 2014 at 4:29 PM, Kenneth Wolcott kennethwolc...@gmail.com wrote: Well, I had to look at http://perldoc.perl.org/perlrequick.html#Extracting-matches to find out how much I had forgotten about extracting matches from a regex :-) This might be inefficient, but it seems to work:

Match HTML div ...... /dv string over multiple

2014-11-18 Thread mimic...@gmail.com
I am trying to extract a table (table class=trtd.. until /table) and its content from an HTML file. With the file I have something like this div id=product class=product table border=0 cellspacing=0 cellpadding=0 class=prodc title=Product . . . /table /div There could be more that one

Re: Match HTML div ...... /dv string over multiple

2014-11-18 Thread Octavian Rasnita
perldoc HTML::Element --Octavian - Original Message - From: mimic...@gmail.com To: beginners@perl.org Sent: Tuesday, November 18, 2014 10:22 PM Subject: Match HTML div .. /dv string over multiple I am trying to extract a table (table class=trtd.. until /table

Re: Match HTML div ...... /dv string over multiple

2014-11-18 Thread Charles DeRykus
On Tue, Nov 18, 2014 at 12:22 PM, mimic...@gmail.com mimic...@gmail.com wrote: I am trying to extract a table (table class=trtd.. until /table) and its content from an HTML file. With the file I have something like this div id=product class=product table border=0 cellspacing=0

Re: Match HTML div ...... /dv string over multiple

2014-11-18 Thread Lars Noodén
On Tue, Nov 18, 2014 at 12:22 PM, mimic...@gmail.com mimic...@gmail.com wrote: I am trying to extract a table (table class=trtd.. until /table) and its content from an HTML file. Because there can be nested tables and other elements that can throw off simple regex parsing, I would try

using string as module

2014-11-08 Thread Patton, Billy N
I currently have something like this use MyFoo::ABCBar; use MyFoo::DEFBar; use MyFoo::HIJBar; my $fooABC = MyFoo::ABCBar-new(); … What I would like to do is foreach $pgm ( ‘ABC’ , ‘DEF’ , ‘HIJ’) { my $foo = MyFoo::{$pgm}Bar-new; … } This gives me an error. What is the correct syntax?

Re: using string as module

2014-11-08 Thread Ron Bergin
Patton, Billy N wrote: I currently have something like this use MyFoo::ABCBar; use MyFoo::DEFBar; use MyFoo::HIJBar; my $fooABC = MyFoo::ABCBar-new(); … What I would like to do is foreach $pgm ( ‘ABC’ , ‘DEF’ , ‘HIJ’) { my $foo = MyFoo::{$pgm}Bar-new; … } This

Re: using string as module

2014-11-08 Thread Shlomi Fish
Hi Billy, please reply to all recipients. On Fri, 7 Nov 2014 13:17:19 + Patton, Billy N billy.pat...@h3net.com wrote: I currently have something like this use MyFoo::ABCBar; use MyFoo::DEFBar; use MyFoo::HIJBar; my $fooABC = MyFoo::ABCBar-new(); … What I would like to do is

Re: using string as module

2014-11-08 Thread Uri Guttman
= MyFoo::{$pgm}Bar-new; … } This gives me an error. What is the correct syntax? I don't see any valid reason why you'd want to do that, but if that's what you want, you could accomplish it with the use of eval. my $foo = eval MyFoo::${pgm}Bar-new; ewww. never use string eval for something

Re: using string as module

2014-11-08 Thread Ron Bergin
Uri Guttman wrote: On 11/08/2014 10:40 AM, Ron Bergin wrote: you could accomplish it with the use of eval. my $foo = eval MyFoo::${pgm}Bar-new; ewww. never use string eval for something as simple as that. my $foo = MyFoo::${pgm}Bar-new() ; that is just fine there. the class in a class

Re: using string as module

2014-11-08 Thread Kent Fredric
On 9 November 2014 05:27, Ron Bergin r...@i.frys.com wrote: In fact, I almost never use or suggest using eval. eval itself is not evil. Its just *string* eval becuase that involves arbitrary code interpolation. Non-string eval is of course potentially written as try in other languages

Re: using string as module

2014-11-08 Thread Shawn H Corey
On Sat, 8 Nov 2014 17:48:31 +0200 Shlomi Fish shlo...@shlomifish.org wrote: The correct syntax is simply (untested): my $foo = MyFoo::${pgm}Bar-new; FYI: That is called a symbolic reference. For more information, see `perldoc perlref` and search for /Symbolic references/ BTW, symbolic

Re: using string as module

2014-11-08 Thread Uri Guttman
` and search for /Symbolic references/ BTW, symbolic references are not considered good practice. But if you need them, you need them. actually that is not a symref. it is just a class method call with a string. strings are allowed as class names and this works under strict. it is not generating

Re: Search one character against one string

2014-03-13 Thread Alex Chiang
Thanks all, and thanks Nathan for your detailed explanation. Now I know the list got flattened before passing into subroutine. Cheers. --- Regards ! Alex Chiang

Re: Search one character against one string

2014-03-13 Thread Alex Chiang
Thanks for your reply. I know the built-in index function, but I just can't figure out why it gives me the answer I don't expect :D --- Regards ! Alex Chiang

Re: Search one character against one string

2014-03-13 Thread Uri Guttman
On 03/12/2014 05:14 AM, Alex Chiang wrote: Thanks for your reply. I know the built-in index function, but I just can't figure out why it gives me the answer I don't expect :D you shouldn't expect some answer without checking the documentation. index is well documented so you must be looking

Search one character against one string

2014-03-12 Thread Alex Chiang
Hi there, I got a wired bug with the following perl script: 35 # return non-negative value if particular character is in string array 36 # otherwise, return -1 sub is_in_string { 38 # @s: string array, $c: character 39 # passing array into sub 40 my @s = @_[0]; my $c = $_[1]; 41 for my

Re: Search one character against one string

2014-03-12 Thread Bob goolsby
with the following perl script: 35 # return non-negative value if particular character is in string array 36 # otherwise, return -1 sub is_in_string { 38 # @s: string array, $c: character 39 # passing array into sub 40 my @s = @_[0]; my $c = $_[1]; 41 for my $i (@s) { if ($c eq $i) {return 1

Re: Search one character against one string

2014-03-12 Thread Robert Wohlfarth
On Tue, Mar 11, 2014 at 11:58 PM, Alex Chiang pigfly...@gmail.com wrote: sub is_in_string { 38 # @s: string array, $c: character 39 # passing array into sub 40 my @s = @_[0]; my $c = $_[1]; snip... 44 my @ar = qw(t d s); 45 my $c = d; 46 my $res = is_in_string( @ar, $c

Re: Search one character against one string

2014-03-12 Thread Jing Yu
Is @_[0] even legit? On 12 Mar 2014, at 04:58, Alex Chiang pigfly...@gmail.com wrote: Hi there, I got a wired bug with the following perl script: 35 # return non-negative value if particular character is in string array 36 # otherwise, return -1 sub is_in_string { 38 # @s

Re: Search one character against one string

2014-03-12 Thread Nathan Hilterbrand
/2014 10:15 AM, Jing Yu wrote: Is @_[0] even legit? On 12 Mar 2014, at 04:58, Alex Chiang pigfly...@gmail.com mailto:pigfly...@gmail.com wrote: Hi there, I got a wired bug with the following perl script: 35 # return non-negative value if particular character is in string array 36 # otherwise

String in Array

2014-02-20 Thread Matt
Having trouble making this work. my @alarm = (xyz, abc); my $name = ab; unless (grep {/$name/} @alarm) { # do this } Since ab is contained in the array I want it to NOT 'do this'. What have I got wrong? -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail:

Re: String in Array

2014-02-20 Thread Peter Gordon
On Thu, 20 Feb 2014 13:04:56 -0600, Matt wrote: Having trouble making this work. my @alarm = (xyz, abc); my $name = ab; unless (grep {/$name/} @alarm) { # do this } Since ab is contained in the array I want it to NOT 'do this'. What have I got wrong? Use word boundaries #!/usr/bin/perl -w use

Re: String in Array

2014-02-20 Thread Uri Guttman
On 02/20/2014 02:04 PM, Matt wrote: Having trouble making this work. my @alarm = (xyz, abc); my $name = ab; unless (grep {/$name/} @alarm) { # do this } Since ab is contained in the array I want it to NOT 'do this'. What have I got wrong? can you show this not working? it looks good to me.

Re: String in Array

2014-02-20 Thread Matt
Having trouble making this work. my @alarm = (xyz, abc); my $name = ab; unless (grep {/$name/} @alarm) { # do this } Since ab is contained in the array I want it to NOT 'do this'. What have I got wrong? If I set 'my $name = abc;' it seems to match. But I want to match on ab as well.

Re: String in Array

2014-02-20 Thread Peter Gordon
On Thu, 20 Feb 2014 15:05:42 -0600, Matt wrote: my @alarm = (xyz, abc); my $name = ab; unless (grep {/$name/} @alarm) { # do this } If I set 'my $name = abc;' it seems to match. But I want to match on ab as well. It appears to do this already. #!/usr/bin/perl -w use 5.14.0; my @alarm = (xyz,

Re: Turn part of a string into a single newline

2014-02-14 Thread 巍俊葛
Hi Parys, Your statement $joinedDNA =~ s/\R//g; will remove new line in the string. You may remove this statement. thanks, Kimi On 14 February 2014 15:48, Parysatis Sachs parysatissa...@gmail.com wrote: Hi everyone! I'm new to this mailing list as well as to programming and Perl

Re: Turn part of a string into a single newline

2014-02-14 Thread Shaji Kalidasan
Dear Parys, Here is one way to do it [code] use strict; use warnings; my $str = agctagccgagctaNNatggctaNNNatgtgaNNatg; $str =~ s/N+/\n/g; ### #Print the string as is (commented out) #print $str, \n; ### print '-' x 40,\n; #Split the string

Re: Turn part of a string into a single newline

2014-02-14 Thread Bill McCormick
a very long string with lots of Ns in it, like this: agctagccgagctaNNatggctaNNNatgtgaNNatg So, I want to get rid of the Ns and get ONE SINGLE newline for each group of Ns So far I've managed to do this: if ($joinedDNA =~ s/N+/\n/g) { $joinedDNA =~ s/\R//g; } But now I have

Re: Turn part of a string into a single newline

2014-02-14 Thread Brian Fraser
On Fri, Feb 14, 2014 at 2:14 PM, Bill McCormick wpmccorm...@gmail.comwrote: Is this your homework? Does it matter? They've shown their work, what they expected to happen and what happened instead. I think the only missing bit would've been I checked in X documentation and couldn't find the

Re: Turn part of a string into a single newline

2014-02-14 Thread Bill McCormick
On 2/14/2014 3:39 AM, kimi ge(巍俊葛) wrote: Hi Parys, Your statement $joinedDNA =~ s/\R//g; will remove new line in the string. You may remove this statement. Yea, I don't see that you need that either. maybe you were just trying to get a new line at then end? $joinedDNA =~ s/N+|$/\n/g

Re: Turn part of a string into a single newline

2014-02-14 Thread John W. Krahn
Parysatis Sachs wrote: Hi everyone! Hello, I'm new to this mailing list as well as to programming and Perl in general. So there is a chance I might ask relatively stupid questions with very obvious answers... Please bear with me! So, here it goes: I have a very long string with lots of Ns

Turn part of a string into a single newline

2014-02-13 Thread Parysatis Sachs
Hi everyone! I'm new to this mailing list as well as to programming and Perl in general. So there is a chance I might ask relatively stupid questions with very obvious answers... Please bear with me! So, here it goes: I have a very long string with lots of Ns in it, like

multiplier in replacement string

2014-02-05 Thread Jorge Almeida
$s=ab; $s=~s/a/AA/; # $s is now AAb I would like to achieve the same with something similar to the x multiplier: $n=2; $s=Ax$n.b; # $s is AAb $s=ab; $n=2; $s=~s/a/Ax$n/; # doesn't work, of course; $s is Ax2b Is it possible at all? Thanks Jorge Almeida -- To unsubscribe, e-mail:

Re: multiplier in replacement string

2014-02-05 Thread Shawn H Corey
On Wed, 5 Feb 2014 19:52:07 + Jorge Almeida jjalme...@gmail.com wrote: $s=ab; $s=~s/a/AA/; # $s is now AAb I would like to achieve the same with something similar to the x multiplier: $n=2; $s=Ax$n.b; # $s is AAb $s=ab; $n=2; $s=~s/a/Ax$n/; # doesn't work, of course; $s is

Re: multiplier in replacement string

2014-02-05 Thread Uri Guttman
On 02/05/2014 02:52 PM, Jorge Almeida wrote: $s=ab; $s=~s/a/AA/; # $s is now AAb I would like to achieve the same with something similar to the x multiplier: $n=2; $s=Ax$n.b; # $s is AAb $s=ab; $n=2; $s=~s/a/Ax$n/; # doesn't work, of course; $s is Ax2b you need the /e modifier on s///. it

Re: multiplier in replacement string

2014-02-05 Thread Jorge Almeida
On Wed, Feb 5, 2014 at 8:11 PM, Uri Guttman u...@stemsystems.com wrote: On 02/05/2014 02:52 PM, Jorge Almeida wrote: $s=ab; $s=~s/a/AA/; # $s is now AAb I would like to achieve the same with something similar to the x multiplier: $n=2; $s=Ax$n.b; # $s is AAb you need the /e modifier

Re: string match question

2013-08-21 Thread Natxo Asenjo
with a text string you haven't thought of, or an update to the device firmware. Rob -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/

Re: string match question

2013-08-21 Thread Matthew K
- From: Natxo Asenjo natxo.ase...@gmail.com To: beginners@perl.org Sent: Wednesday, August 21, 2013 11:32 AM Subject: Re: string match question *snip* I agree with Rob Dixon I should be parsing

Re: string match question

2013-08-21 Thread Natxo Asenjo
: Re: string match question *snip* I agree with Rob Dixon I should be parsing the html, but unfortunately getting it was proving more complicated than this. *snip* -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http

Re: string match question

2013-08-21 Thread Rob Dixon
On 21/08/2013 18:32, Natxo Asenjo wrote: hi, thanks all for your advice. I have just used one of your suggested regex to accomplish this task: if ( $text =~ /.*(critical alarm.*?)\./i ) { my $message = $1; print $message, \n; } This captures everything starting with critical alarm

string match question

2013-08-20 Thread Natxo Asenjo
the submit_form method, by the way). Then I save the text of the website in a variable like this: my $text = $mech-text(); if ( $text =~ /critical alarm/i ) { print Bingo\n; } This works, if I unplug something I get the critical alarm, I replug the stuff and the string does not match anymore

Re: string match question

2013-08-20 Thread Jim Gibson
the critical alarm, I replug the stuff and the string does not match anymore. $text has this (very long line): APC | UPS Network Management Card 2Skip to Main ContentUPS Network Management Card 2Smart-UPS/Matrix Application 1user | English | Log Off | Help

Re: string match question

2013-08-20 Thread Matthew K
- From: Natxo Asenjo natxo.ase...@gmail.com To: beginners@perl.org Sent: Tuesday, August 20, 2013 8:02 AM Subject: string match question hi, for a nagios (monitoring system) check I need to scrape a web site (this is for a network device, a UPS, whatever). This particular

Re: string match question

2013-08-20 Thread Shawn H Corey
On Tue, 20 Aug 2013 16:02:50 +0200 Natxo Asenjo natxo.ase...@gmail.com wrote: I am only interested in the text '1 Critical Alarm PresentA site wiring fault exists'; is it possible to match this is a simple way (in fact, the text after 'Critical Alarm Present' may vary, it would be awesome to

Re: string match question

2013-08-20 Thread Rob Dixon
is absolutely the right way to do this. It's not that hard. If you put a sample of the HTML up (perhaps on pastebin?) then someone will code it for you. Better that way than writing some unreliable regular expression that may fail one day with a text string you haven't thought of, or an update to the device

  1   2   3   4   5   6   7   8   9   10   >