Re: [ubuntu-uk] [OT] Quick Perl question
> New line characters in the substitution string, perhaps? Dot doesn't > match those unless you modify the line: > > $solar_info =~ s/<\/solar>.*/,/s; > Kevin, may have something there - there is an inexplicable white space when the tags are doubled up. I.e. 1,2,3,4,5 6,7,8,9,0 when it is doubled up I want to end up with just 1,2,3,4,5, so I can split it out into an array. I'll give the abaove a bash (no pun intended) when I get home tonight... Cheers, Lee -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] [OT] Quick Perl question
New line characters in the substitution string, perhaps? Dot doesn't match those unless you modify the line: $solar_info =~ s/<\/solar>.*/,/s; -- Kevin Safford -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] [OT] Quick Perl question...
I'm pretty sure you need to avoid matching the start of the 2nd tag, otherwise text of the form: abcdefghij Will be extracted as: abcdefghij E.g. Use a character class that avoids matching the start of a tag: $solar_info =~ s!([^<]*)!$1!g; -- Matthew Bassett Sorry about the top posting- am replying from my phone. -Original Message- From: Matt Wheeler Sent: 12/07/2010 23:46:32 Subject: Re: [ubuntu-uk] [OT] Quick Perl question... [some pruned text] You could remove both the start and end tags with something like $solar_info =~ s!(.*)!$1!; (note I'm also using ! instead of / so I don't have to escape the /) -- Matt Wheeler m...@funkyhat.org -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/ -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] [OT] Quick Perl question...
Rather than removing the , pair as separate actions it might be easier to use them to 'anchor' the start and end of text you want to extract. Try: $solar_info =~ s/([^<]*)<\/solar>/$1\n/; This matches everything between the ... pair, and replaces it with the text in between- it also sticks an extra newline on the end for where you have 'joined' lines - it should be easy to remove blank lines later. I'm a bit rusty: you might want to stick a 'g' on the very end (after the replacement expression) to make it match more than once on the same line. $solar_info =~ s/([^<]*)<\/solar>/$1\n/g; Let us know how you get on. -- Matthew Bassett Sorry about the top posting- am replying from my phone. -Original Message- From: LeeGroups Sent: 12/07/2010 22:55:38 Subject: Re: [ubuntu-uk] [OT] Quick Perl question... >> $solar_info =~ s/<\/solar>.*/,/; >> >> From my tinkerings, this should find the string in the string >> $solar_info, and then remove it and any number of following characters >> (the .*) and then replace them with a ",". >> Except that it doesn't. It hacks out the and replaces it with a >> , but leaves the rest of the string intact... Much to my annoyance... :| >> > What's the input string? The following code simply prints "," for me > not ",abcdef" as you suggest it would: > $test = "abcdef"; > $test =~ s/<\/solar>.*/,/; > print $test; This input 8,27.31,28.68,28.81,0.00,0.00,0 It need to be -- 8,27.31,28.68,28.81,0.00,0.00,0 Another line chops off the . The problem is that occasionally there is rubbish on the end of the line, or even another line appended to the end of the first... -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/ -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] [OT] Quick Perl question...
On 12 July 2010 22:55, LeeGroups wrote: > This input 8,27.31,28.68,28.81,0.00,0.00,0 > It need to be -- > 8,27.31,28.68,28.81,0.00,0.00,0 > > Another line chops off the . > The problem is that occasionally there is rubbish on the end of the > line, or even another line appended to the end of the first... You could remove both the start and end tags with something like $solar_info =~ s!(.*)!$1!; (note I'm also using ! instead of / so I don't have to escape the /) -- Matt Wheeler m...@funkyhat.org -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] [OT] Quick Perl question...
So, why not do /(.*)<\/solar>/ ? -- Jon "TheNiceGuy" Spriggs On 12 Jul 2010 22:56, "LeeGroups" wrote: >> $solar_info =~ s/<\/solar>.*/,/; >> >> From my tinkerings, this should find the string ... > What's the input string? The following code simply prints "," for me > not ",abcdef" as you sugges... This input 8,27.31,28.68,28.81,0.00,0.00,0 It need to be -- 8,27.31,28.68,28.81,0.00,0.00,0 Another line chops off the . The problem is that occasionally there is rubbish on the end of the line, or even another line appended to the end of the first... -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki... -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] [OT] Quick Perl question...
>> $solar_info =~ s/<\/solar>.*/,/; >> >> From my tinkerings, this should find the string in the string >> $solar_info, and then remove it and any number of following characters >> (the .*) and then replace them with a ",". >> Except that it doesn't. It hacks out the and replaces it with a >> , but leaves the rest of the string intact... Much to my annoyance... :| >> > What's the input string? The following code simply prints "," for me > not ",abcdef" as you suggest it would: > $test = "abcdef"; > $test =~ s/<\/solar>.*/,/; > print $test; This input 8,27.31,28.68,28.81,0.00,0.00,0 It need to be -- 8,27.31,28.68,28.81,0.00,0.00,0 Another line chops off the . The problem is that occasionally there is rubbish on the end of the line, or even another line appended to the end of the first... -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/
Re: [ubuntu-uk] [OT] Quick Perl question...
On 12 July 2010 21:12, LeeGroups wrote: > $solar_info =~ s/<\/solar>.*/,/; > > From my tinkerings, this should find the string in the string > $solar_info, and then remove it and any number of following characters > (the .*) and then replace them with a ",". > Except that it doesn't. It hacks out the and replaces it with a > , but leaves the rest of the string intact... Much to my annoyance... :| > > Any clues? What's the input string? The following code simply prints "," for me not ",abcdef" as you suggest it would: $test = "abcdef"; $test =~ s/<\/solar>.*/,/; print $test; Tom p.s. I don't know perl but I thought I'd have a play anyway -- ubuntu-uk@lists.ubuntu.com https://lists.ubuntu.com/mailman/listinfo/ubuntu-uk https://wiki.ubuntu.com/UKTeam/