C
cp
I copied a webpage that had a color guide that I liked. I wanted to extract
the color names and codes and make a list of name alternating with code,
which, of course, could be made into a hash or saved in a file or whatever.
Below is some random clippings from the html so you can see what I am
working with. Below that is the foreach loop that goes through and looks
for the color name and color code. The html file is already loaded into
@data. I thought that it worked fine until I realized that some colors
were missed. I then observed that the first color to be picked up on a
line was picked up but the remaining colors on the same line were skipped.
I thought that adding the g modifier at the end of the regex would fix it
but it produced the same exact output. Any suggestions would be greatly
appreciated.
class=s><br> <td>mediumseagreen (<a href="colorsvg.html">SVG</a>)
#3CB371<td bgcolor="#3CB371" class=s><td>gray24 #3D3D3D<td
bgcolor="#3D3D3D" class=s>^M
<tr align=right><td>cobalt #3D59AB<td bgcolor="#3D59AB"
class=s><br> <td>cobaltgreen #3D9140<td bgcolor="#3D9140"
class=s><td>gray25 #404040<td bgcolor="#404040" class=s>^M
<tr align=right><td>dodgerblue4 #104E8B<td bgcolor="#104E8B"
class=s><br> <td>ultramarine #120A8F<td bgcolor="#120A8F"
class=s><td>gray7 #121212<td bgcolor="#121212" class=s>^M
foreach(@data)
{
next if not /td\>(\S+\s?\S*)\s*(\#[[:xdigit:]]+)\<td/g;
my $s1 = "$1\n";
my $s2 = "$2\n";
push @output,($s1,$s2);
}
the color names and codes and make a list of name alternating with code,
which, of course, could be made into a hash or saved in a file or whatever.
Below is some random clippings from the html so you can see what I am
working with. Below that is the foreach loop that goes through and looks
for the color name and color code. The html file is already loaded into
@data. I thought that it worked fine until I realized that some colors
were missed. I then observed that the first color to be picked up on a
line was picked up but the remaining colors on the same line were skipped.
I thought that adding the g modifier at the end of the regex would fix it
but it produced the same exact output. Any suggestions would be greatly
appreciated.
class=s><br> <td>mediumseagreen (<a href="colorsvg.html">SVG</a>)
#3CB371<td bgcolor="#3CB371" class=s><td>gray24 #3D3D3D<td
bgcolor="#3D3D3D" class=s>^M
<tr align=right><td>cobalt #3D59AB<td bgcolor="#3D59AB"
class=s><br> <td>cobaltgreen #3D9140<td bgcolor="#3D9140"
class=s><td>gray25 #404040<td bgcolor="#404040" class=s>^M
<tr align=right><td>dodgerblue4 #104E8B<td bgcolor="#104E8B"
class=s><br> <td>ultramarine #120A8F<td bgcolor="#120A8F"
class=s><td>gray7 #121212<td bgcolor="#121212" class=s>^M
foreach(@data)
{
next if not /td\>(\S+\s?\S*)\s*(\#[[:xdigit:]]+)\<td/g;
my $s1 = "$1\n";
my $s2 = "$2\n";
push @output,($s1,$s2);
}