slurp

How do I read a file's contents into a Perl scalar?

久未见 提交于 2019-12-25 00:32:54
问题 what i am trying to do is get the contents of a file from another server. Since im not in tune with perl, nor know its mods and functions iv'e gone about it this way: my $fileContents; if( $md5Con =~ m/\.php$/g ) { my $ftp = Net::FTP->new($DB_ftpserver, Debug => 0) or die "Cannot connect to some.host.name: $@"; $ftp->login($DB_ftpuser, $DB_ftppass) or die "Cannot login ", $ftp->message; $ftp->get("/" . $root . $webpage, "c:/perlscripts/" . md5_hex($md5Con) . "-code.php") or die $ftp->message;

Slurping http://foobar.mp3 that redirects to http://fizzbar.mp3 in Clojure

不羁的心 提交于 2019-12-23 20:53:01
问题 I am trying to programatically download mp3 files from this rss feed. When I open an url such as: http://menlochurch.podbean.com/mf/feed/5gv2gb/170219_jortberg.mp3 it redirects to an url like: http://s62.podbean.com/pb/67f34563539acbe87b9566ecc5738d57/58aeff8e/data4/fs145/948579/uploads/170219_jortberg.mp3 If I curl the first url it downloads an empty file. If I curl -L the first url it correctly downloads the file. If I curl the second url it correctly downloads the file. If I slurp the

Reliable Perl encoding with File::Slurp

你说的曾经没有我的故事 提交于 2019-12-12 01:54:34
问题 I need to replace every occurrence of http:// with // in a file. The file may be (at least) in UTF-8 , CP1251 , or CP1255 . Does the following work? use File::Slurp; my $Text = read_file($File, binmode=>':raw'); $Text =~ s{http://}{//}gi; write_file($File, {atomic=>1, binmode=>':raw'}, $Text); It seems correct, but I need to be sure that the file will not be damaged whatever encoding it has. Please help me to be sure. 回答1: This answer won't make you sure, though I hope it can help. I don't

Read file into variable in Perl [duplicate]

a 夏天 提交于 2019-12-08 14:54:26
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: What is the best way to slurp a file into a string in Perl? Is this code a good way to read the contents of a file into a variable in Perl? It works, but I'm curious if there is a better practice I should be using. open INPUT, "input.txt"; undef $/; $content = <INPUT>; close INPUT; $/ = "\n"; 回答1: I think common practice is something like this: my $content; open(my $fh, '<', $filename) or die "cannot open file

How to set up a robot.txt which only allows the default page of a site

家住魔仙堡 提交于 2019-12-03 08:35:24
问题 Say I have a site on http://example.com. I would really like allowing bots to see the home page, but any other page need to blocked as it is pointless to spider. In other words http://example.com & http://example.com/ should be allowed, but http://example.com/anything and http://example.com/someendpoint.aspx should be blocked. Further it would be great if I can allow certain query strings to passthrough to the home page: http://example.com?okparam=true but not http://example.com

Make a parent div webkit-filter not affect children

我怕爱的太早我们不能终老 提交于 2019-11-27 14:42:47
I'm using a very fancy webkit filter to make background-images grayscale, and on hover over the images become color. Here's the filter filter: none; -webkit-filter: grayscale(0); transition: opacity .3s ease-in-out; -moz-transition: opacity .3s ease-in-out; -webkit-transition: opacity .3s ease-in-out; As you can see, there's even a 'transition' property so that the image has a smooth fading transition into full color. The problem that I'm having is that the div I'm applying it to is also affecting the child text positioned inside the div, turning the text into grayscale as well. This is a

Make a parent div webkit-filter not affect children

ぐ巨炮叔叔 提交于 2019-11-26 16:43:18
问题 I'm using a very fancy webkit filter to make background-images grayscale, and on hover over the images become color. Here's the filter filter: none; -webkit-filter: grayscale(0); transition: opacity .3s ease-in-out; -moz-transition: opacity .3s ease-in-out; -webkit-transition: opacity .3s ease-in-out; As you can see, there's even a 'transition' property so that the image has a smooth fading transition into full color. The problem that I'm having is that the div I'm applying it to is also

In Perl, how can I read an entire file into a string?

人盡茶涼 提交于 2019-11-26 14:19:17
I'm trying to open an .html file as one big long string. This is what I've got: open(FILE, 'index.html') or die "Can't read file 'filename' [$!]\n"; $document = <FILE>; close (FILE); print $document; which results in: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN However, I want the result to look like: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> This way I can search the entire document more easily. Sinan Ünür Add: local $/; before