CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Strange behavior of script which get links by pattern

 



Master_Sergius
Novice

Aug 30, 2018, 6:13 AM

Post #1 of 5 (1716 views)
Strange behavior of script which get links by pattern Can't Post

Hello, Perl community.

I want to install automatically all needed packages from list, so I've tried to write following script (currently it should print only full package name to check if that's what I need):


Code
my $REPO_URL = 'http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/7.3-RELEASE/packages/All/'; 

my @PACKAGES = ('openssh',
'python2.6',
'qt4',
...
#here comes long list about 50 packages
);

my $packages_page = `curl $REPO_URL`;

# this is a test if urls are valid
foreach my $package (@PACKAGES) {
print "$package: ";
$packages_page =~ m/HREF="(.*?\Q$package\E.*?\.tbz)"/gi;
print "tbz: $1\n";
}


And some weird stuff is going on, in output some packages are missing (For example - 'bbftp-3.0.2'):

openssh: tbz: OpenSSH-askpass-1.2.4.1.tbz
python26: tbz: python26-2.6.4.tbz
bbftp-3.0.2: tbz:
qt4: tbz: gtk-qt4-engine-1.1_3.tbz
adl: tbz: gunfudeadlands-1.00_1.tbz
lost: tbz: lostirc-0.4.6_7.tbz

But after I just copy-pasted this element again into array it can find it in second try:

openssh: tbz: OpenSSH-askpass-1.2.4.1.tbz
python26: tbz: python26-2.6.4.tbz
bbftp-3.0.2: tbz:
bbftp-3.0.2: tbz: bbftp-3.0.2.tbz
qt4: tbz: gtk-qt4-engine-1.1_3.tbz
adl: tbz: gunfudeadlands-1.00_1.tbz
lost: tbz: lostirc-0.4.6_7.tbz

So, the questions is - what's going on here? Where is the mistake, what I should escape, maybe it is not enough to use \Q and \E - \Q$package\E and some symbols still need to be escaped?


FishMonger
Veteran / Moderator

Aug 30, 2018, 9:05 AM

Post #2 of 5 (1709 views)
Re: [Master_Sergius] Strange behavior of script which get links by pattern [In reply to] Can't Post

Is your @PACKAGES array defined like that, or are you using the full filenames?

If you are using partial names, how do you want to handle multiple matches? For example, currently there are 87 packages with qt4 in the name. Do you want the first one found or the last one or all of them?

Also, as a personal preference, I would use one of Perl's modules to get the links instead of shelling out to curl.


Master_Sergius
Novice

Aug 30, 2018, 9:11 AM

Post #3 of 5 (1705 views)
Re: [FishMonger] Strange behavior of script which get links by pattern [In reply to] Can't Post

Oh, it may be the key to solution. Yes, I need to see different versions of the same package and choose only what I need. But problem appears not with qt4, or it is related somehow?


FishMonger
Veteran / Moderator

Aug 30, 2018, 9:13 AM

Post #4 of 5 (1704 views)
Re: [Master_Sergius] Strange behavior of script which get links by pattern [In reply to] Can't Post

Here's an example using one of the modules.


Code
#!/usr/bin/perl 

use warnings;
use strict;
use HTML::SimpleLinkExtor;
use Data::Dumper;


my $REPO_URL = 'http://ftp-archive.freebsd.org/pub/FreeBSD-Archive/old-releases/i386/7.3-RELEASE/packages/All/';

my @PACKAGES = ('openssh',
'python2.6',
'qt4',
'bbftp',
);

my $extor = HTML::SimpleLinkExtor->new();
$extor->parse_url($REPO_URL);

my @links = $extor->href;

my $pkgs = join '|', @PACKAGES;
my @want = grep { /$pkgs/ } @links; # the regex could be expanded as needed

print Dumper \@want;


Outputs

Code
root@99-91-rkb02:~# ./get_links.pl  
$VAR1 = [
'avahi-qt4-0.6.25.tbz',
'bbftp-3.0.2.tbz',
'gtk-qt4-engine-1.1_3.tbz',
'openssh-portable-5.2.p1_2%2c1.tbz',
'pinentry-qt4-0.7.6_2.tbz',
'poppler-qt4-0.12.3_1.tbz',
'py26-qt4-4.7.tbz',
'py26-qt4-assistant-4.7_1%2c1.tbz',
'py26-qt4-core-4.7%2c1.tbz',
'py26-qt4-dbus-4.7%2c1.tbz',
'py26-qt4-demo-4.7_1%2c1.tbz',
'py26-qt4-designer-4.7_1%2c1.tbz',
'py26-qt4-designerplugin-4.7_1%2c1.tbz',
'py26-qt4-doc-4.7%2c1.tbz',
'py26-qt4-gui-4.7_1%2c1.tbz',
'py26-qt4-help-4.7_1.tbz',
'py26-qt4-multimedia-4.7.tbz',
'py26-qt4-network-4.7%2c1.tbz',
'py26-qt4-opengl-4.7_1%2c1.tbz',
'py26-qt4-phonon-4.7.tbz',
'py26-qt4-qscintilla2-2.4.2_2%2c1.tbz',
'py26-qt4-script-4.7%2c1.tbz',
'py26-qt4-scripttools-4.7%2c1.tbz',
'py26-qt4-sql-4.7_1%2c1.tbz',
'py26-qt4-svg-4.7_1%2c1.tbz',
'py26-qt4-test-4.7_1%2c1.tbz',
'py26-qt4-webkit-4.7_1.tbz',
'py26-qt4-xml-4.7%2c1.tbz',
'py26-qt4-xmlpatterns-4.7.tbz',
'qgit-qt4-2.2_1.tbz',
'qt4-4.6.1_1.tbz',
'qt4-accessible-4.6.1.tbz',
'qt4-assistant-4.6.1.tbz',
'qt4-assistant-adp-4.6.1.tbz',
'qt4-clucene-4.6.1.tbz',
'qt4-codecs-cn-4.6.1.tbz',
'qt4-codecs-jp-4.6.1.tbz',
'qt4-codecs-kr-4.6.1.tbz',
'qt4-codecs-tw-4.6.1.tbz',
'qt4-corelib-4.6.1.tbz',
'qt4-dbus-4.6.1.tbz',
'qt4-designer-4.6.1.tbz',
'qt4-doc-4.6.1.tbz',
'qt4-gui-4.6.1.tbz',
'qt4-help-4.6.1.tbz',
'qt4-help-tools-4.6.1.tbz',
'qt4-iconengines-4.6.1.tbz',
'qt4-imageformats-4.6.1_1.tbz',
'qt4-inputmethods-4.6.1.tbz',
'qt4-l10n-4.6.1.tbz',
'qt4-libQtAssistantClient-4.6.1.tbz',
'qt4-linguist-4.6.1.tbz',
'qt4-makeqpf-4.6.1.tbz',
'qt4-moc-4.6.1.tbz',
'qt4-multimedia-4.6.1.tbz',
'qt4-mysql-plugin-4.6.1.tbz',
'qt4-network-4.6.1.tbz',
'qt4-odbc-plugin-4.6.1.tbz',
'qt4-opengl-4.6.1.tbz',
'qt4-phonon-4.6.1.tbz',
'qt4-phonon-gst-4.6.1.tbz',
'qt4-pixeltool-4.6.1.tbz',
'qt4-porting-4.6.1.tbz',
'qt4-psql-plugin-4.6.1.tbz',
'qt4-qdbusviewer-4.6.1.tbz',
'qt4-qdoc3-4.6.1.tbz',
'qt4-qmake-4.6.1.tbz',
'qt4-qt3support-4.6.1.tbz',
'qt4-qtconfig-4.6.1.tbz',
'qt4-qtdemo-4.6.1_1.tbz',
'qt4-qtestlib-4.6.1.tbz',
'qt4-qvfb-4.6.1.tbz',
'qt4-rcc-4.6.1.tbz',
'qt4-script-4.6.1.tbz',
'qt4-scripttools-4.6.1.tbz',
'qt4-sql-4.6.1.tbz',
'qt4-sqlite-plugin-4.6.1.tbz',
'qt4-sqlite2-plugin-4.6.1.tbz',
'qt4-svg-4.6.1.tbz',
'qt4-uic-4.6.1.tbz',
'qt4-uic3-4.6.1.tbz',
'qt4-webkit-4.6.1.tbz',
'qt4-xml-4.6.1.tbz',
'qt4-xmlpatterns-4.6.1.tbz',
'qt4-xmlpatterns-tool-4.6.1.tbz',
'qt4pas-2.1.tbz',
'qwtplot3d-qt4-0.2.7_2.tbz',
'scim-bridge-qt4-0.4.15_1.tbz',
'telepathy-qt4-0.2.1_1.tbz'
];



Master_Sergius
Novice

Aug 30, 2018, 9:18 AM

Post #5 of 5 (1702 views)
Re: [FishMonger] Strange behavior of script which get links by pattern [In reply to] Can't Post

Wow, great! I'll try to experiment with all these stuff and reply tomorrow, probably.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives