#!/usr/bin/env perl use strict; my ($dir, $url, $content); $dir = '/tmp'; $url = 'http://dir.yahoo.co.jp/Computers_and_Internet/Internet/World_Wide_Web/Searching_the_Web/All_in_One_Search_Pages/'; $content = 'Yahoo! JAPAN Meta Search!!!'; my $path = &Lib_url2dir($dir, $url, $content); print $path . "\n"; sub Lib_url2dir { my ($dir, $url, $content) = @_; my $default = 'index.html'; my $path; if ($url =~ m|^http(?:s)?://(.*?)$|) { my @dir = split (/\//, $1); my $flag = 0; my $file; if ($url =~ m|/$|) { $file = $default; } else { $file = pop @dir; } $path = $dir; foreach my $dir (@dir) { $path .= '/' . $dir; if (-d $path) { next; } elsif (-f $path) { $flag = 1; last; } else { my $ch = mkdir $path, 0755; if (!$ch) { $flag = 1; last; } } } if ($flag) { undef $path; } else { $path .= '/' . $file; open (OUT, "> $path"); print OUT $content; close (OUT); } } unless (-f $path) { undef $path; } return $path; }